« first day (1837 days earlier)      last day (3111 days later) » 

7:00 PM
That seems backwards. gifs aren't super intuitive to read and save.
 
image.seek and image.tell seem to be the only methods that deal with "image sequences"
So yeah the only thing you can do is ask what frame you're in, and move to the next frame. Or crash if there isn't one.
It can't save gifs at all AFAICT
 
If you try to show a gif frame, does it show the whole gif, or just the updated part of it? Cuz gifs don't (typically) store the whole frame, just what changed.
I don't have the vocabulary to ask that right, but you get what I mean?
 
I do.
From my randomly browsing through related SO posts, I think it only shows the updated part.
 
I'm just being skepticalish. Gif rendering/saving is in that weird territory between trivial and hard.
 
7:05 PM
@QuestionC Ah yes, the uneasy valley.
 
Where the vistas are nice, but you don't know if they're really worth the effort.
 
TIL about cell indirection in Excel
Vista is never worth the effort.
 
@AdamSmith Why would you ever want that? It just sounds like a recipe for headaches.
 
7:21 PM
Ok, partial success. I can read every frame from this gif, and each frame is fully there, but I don't know how to get the color table.
All I have are a stream of bytes ranging from 0 to 255 with no logical connection to the hues they actually represent
 
@MorganThrapp conditional formatting in my case. I wanted to apply a conditional format to a range of cells that checks if those cells are formulas and apply a background color. There's an ISFORMULA function, but without indirection I don't have a way to refer to "This Cell"
 
@AdamSmith Ahhh, gotcha. When I was reading the docs for it, they mentioned using it over multiple files and that sounded terrible.
 
ISFORMULA(INDIRECT("rc", FALSE)) where the second argument to INDIRECT is True if it's in A1 style and False if it's in R1C1 style
 
7:34 PM
Oh, there it is in the mostly undocumented palette.getdata method.
Programming without a net is when you Google a problem and the top result is a blog post from 2005
 
Sounds like it's time to blog about it.
That's like building the net! :P
 
DSM
Fifteen weeks when three of those weeks are my vacation is not fifteen weeks. #corporatemath (And just to be clear, because it's ambiguous there, this is "time I have to accomplish something", so bigger numbers are better for me.)
 
Trying to get a string descriptor using pyusb and got AttributeError:'Endpoint' object has not attribute 'ctrl_transfer'
i checked the pyusb code but that did no good as i did not quite understand why it did not have a ctrl_transfer
Anyone come upon the issue before?
 
Programming without a net is when your documentation is the object's tab-completion.
 
DSM
I've answered questions on SO just by using tab-completion and ??-style code inspection.
 
7:50 PM
hmmmm. The next codewars kata I'm attempting is Snail Sort. It's an interesting one...
 
Requires login.
Can't sign up because I used all my give-a-damn points for the day on gif decomposition
 
unroll a list of lists clockwise
[[1, 2, 3],
 [4, 5, 6],
 [7, 8, 9]]
 
cool, SO now has custom tabs
 
-> [1, 2, 3, 6, 9, 8, 7, 4, 5]
 
@AdamSmith I had fun doing this one: codewars.com/kata/simple-interactive-interpreter
 
7:57 PM
Oh, I think matrix unrolling was the subject of a gimmie-teh-codes question last week.
I answered it using an unholy mess of trigonometry.
Let's see if I can find it.
My bad, it only iterates through the items on the exterior edge. stackoverflow.com/a/33125516/953482
 
I was thinking about trying to mark the points where the direction of travel chages, and then make some sort of more transparent notation for it. my_matrix.get((x,y) + DOWN) or something
 
I have a similar idea... I'm going to play around with it.
 
@idjaw oh lord I don't even know where to start on that one
I'd have to spend some serious sit down and thinkaboutit time :P
 
It was probably one of the messiest solutions I've written. I even wrote a comment saying something along the lines of "I'm not proud of this...but tests passed"
 
those kinds of solutions are tempting on these, because you know neither you nor anyone else will have to maintain your code
so screw convention, screw commenting, screw descriptive naming. Make the tests pass and collect your points
:P
 
8:08 PM
It just looks like a
 
hahah. That is why I started doing more of the lower level kyu ones, because they were short enough to make a nice solution. Those 1 kyu ones are similar in how convoluted and time consuming they are
 
while True:
  # split/yield top
  # split/yield right
  # split/yield bottom (backwards)
  # split/yeild left (backwards)
kinda problem
 
huh?
 
That's another approach: slice off pieces of the matrix and yield each piece in turn, until nothing remains
 
Just seems... pythony because you know zip abuse is gonna be in there.
 
8:11 PM
I don't abuse zip. It likes it.
 
DSM
Are we given that it's square?
 
yes
Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise.

array = [[1,2,3],
         [4,5,6],
         [7,8,9]]
snail(array) #=> [1,2,3,6,9,8,7,4,5]
 
Ooh, I can think of a nice functional approach that works only on square matrices.
 
knowing the test cases it throws at you, it might still give you a non-square list that needs to be error-cased
 
For certain definitions of "nice"
 
8:13 PM
Can you start a cron sometime in the given future?
 
I don't see why not.
 
sure -- remind me in a few minutes and I'll start one
it's much harder to start a cron sometime in the past
 
One of us is misunderstanding what cron means
When else would cron start something?
 
does python2 have set comprehensions?
 
DSM
8:16 PM
@AdamSmith: yes.
 
@QuestionC more like delay the starting of a cron until some time
 
Air
I should say, the infamous Sweet Cron of Cave Junction... 1, 2, 3, 4, etc.
 
I'm naming lambdas, and using UPPERCASE names. How delightfully against convention.
 
@Air I'm more a fan of pear programming.
 
good old SublimeText
 
8:23 PM
Morgan, I'm telling PyCharm about your infidelity.
 
@idjaw Pfft, that's not me. I'd never use OSx. ;)
 
heheheh
 
Here's my go for snail sort. I wish I could have found a nicer way to rotate a list 90 degrees.
 
ooh that's interesting
 
Not to be confused with transposing a list, which has a number of elegant implementations
and/or zip abuses
 
8:28 PM
I'm definitely going a different route. Mine looks more like pathfinding. Still writing.
 
Is there a way to make a line like i = zip(*i) except the *i arguments are reversed?
 
wouldn't that just be *reversed(i)?
 
i is an iterator...
 
bleh
 
The pathfinding approach is ultimately more performant since it doesn't have to make a zillion copies of the matrix the way mine does
The former is like O(1) memory or something ridiculous
 
8:35 PM
hrm. Owner just came into my office and asked me what my last name was. Apparently I'm getting a company card
 
Do you work at a large office? lol
 
Nevermind, misunderstood.
 
large company, smallish office
office only has ~20 people. About 400 in the company
    import itertools

    RIGHT = lambda loc: (loc[0]+1, loc[1])
    DOWN = lambda loc: (loc[0], loc[1]+1)
    LEFT = lambda loc: (loc[0]-1, loc[1])
    UP = lambda loc: (loc[0], loc[1]-1)

    directions = itertools.cycle([RIGHT, DOWN, LEFT, UP])

    def snail(a):
        result = []
        n = len(a)
        available = {(x, y) for y, x in itertools.product(range(n), repeat=2)}
        cur_cell = (0, 0)
        direction = next(directions)
        while available:
            x, y = cur_cell
 
Ahh, okay. That's more reasonable to not remember the last name of someone then.
 
DSM
@Kevin: how about list(reversed(list(zip(*seq)))).. which I guess is just list(zip(*seq))[::-1] for the rotation?
@AdamSmith: did you get a look when you said it was Smith?
 
8:37 PM
an embarrassed one, yes :P
 
DSM
.. oh, wait. That's anticlockwise, isn't it.
 
def f(x):
    i = iter(x)

    while True:
        top = next(i)

        if len(top) > 0:
            yield from top
        else:
            return

        i = iter(reversed(list(zip(*i))))

a = [[1,2,3],[4,5,6],[7,8,9]]

for i in f(a):
    print(i)
 
not in Python2 :P
 
Could probably be made better but this is a learning yieldterators exercise...
def f(x):
    i = iter(x)

    while True:
        yield from next(i)
        i = iter(reversed(list(zip(*i))))

a = [[1,2,3],[4,5,6],[7,8,9],[10,11,12], [13, 14, 15]]

for i in f(a):
    print(i)
hehe
 
I hate codewars's repl
my stack trace is:
Traceback:
   in
   in run_test
   in snail
IndexError: list index out of range
no idea where the list index could possibly BE out of range
ah of course. Input is [[]]
special-cased and passing tests. Hooray.
 
8:55 PM
@AdamSmith This one was short and sweet: codewars.com/kata/can-you-get-the-loop
 
starred for later :)
 
+1. With that, it's time to head out. rbrb
 
rhubarb
oh apparently numpy is available?
import numpy as np

def snail(array):
    arr = np.array(array)

    if len(arr) < 2:
        return arr.flatten().tolist()

    tp = arr[0, :].tolist()
    rt = arr[1:, -1].tolist()
    bm = arr[-1:, :-1].flatten()[::-1].tolist()
    lt = arr[1:-1, 0] [::-1].tolist()

    return tp + rt + bm + lt + snail(arr[1:-1, 1:-1])
 
DSM
@AdamSmith: could use rot90:
def snail(array):
    arr = np.array(array)
    out = []
    while arr.size:
        r, arr = arr[0], arr[1:]
        arr = np.rot90(arr)
        out.extend(r)
    return out
 
I can fit all I know about numpy on my little finger.
that was someone else's solution
 
DSM
9:07 PM
I tried to do it as a sort, which I know you can do because you can write down the formula for the indices you're iterating over, but I kept getting the arithmetic wrong.
 
10:06 PM
Omnomnom jerk chicken
 
10:48 PM
Welcome @xi_, are you here about the Flask question?
 
@AdamSmith "Input is [[]]" Srsly? I thought it was supposed to be square.
@Ffisegydd At first I read "common jerk chicken" and then I was picturing Fizzy sweltering in Jamaica. Not a pretty sight.
 
11:05 PM
hi one small question, couldnt able to find in google
i have an array say a = [1, 2, 3] now I want always the 'a' should have 5 values if not zero should be appended e.g. a = [1,2,3,0,0]
i tried np.pad but it worls only for 2d
 
yesterday, by davidism
@MorganThrapp (my_data + [None] * max_len)[:max_len]
 
@davidism is it for me ?
 
yes
 
what does none stands for ?
 
That's the placeholder value. ... Why not just try it and see?
 
11:11 PM
yup it works
thanks buddy
 
11:24 PM
@VinodPrime That's a pretty common idiom for padding values. I use it a lot in batch scripts and stuff too to zero fill. Add a bunch of zeroes before a value then slice off the last N characters.
@PatrickMaupin That's a square of size zero, I guess.
 
@AdamSmith [[1]] would be one row with one element in it. But [[]] is one row with zero elements in it.
e.g. not square
 
Cabbage.
 
Let me look up that kata again. I think they mentioned it in the description because I wasn't terribly surprised to see it. I thought my code handled it to begin with (it was testing len(lst) == 0 as the special case instead of len(lst[0]) == 0)
> NOTE 2: The 0x0 (empty matrix) is represented as [[]]
yeah they forewarned me :)
 
OK, that's why you were so calm about it.
When I saw you mention it earlier, my WTF reaction started. (It's still there, but muted with the warning.)
 
@idjaw That was a fun one! I like the top voted answer. Interesting technique (though it's gotta be much slower!)
I feel like if you give my function nonsensical input, it should be allowed to crash. In a normal case I'd raise ValueError, but they wanted return [] so meh
 

« first day (1837 days earlier)      last day (3111 days later) »