Skip to content

Instantly share code, notes, and snippets.

@gerow
gerow / ref.py
Created November 16, 2016 23:23
gerow@gerow0:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l = ['why are lists pass by reference by default in python?']
>>> def f(l):
... l.append('because fuck you')
...
>>> f(l)
>>> l

Keybase proof

I hereby claim:

  • I am gerow on github.
  • I am gerow (https://keybase.io/gerow) on keybase.
  • I have a public key whose fingerprint is 1DE1 5385 516E 3625 0008 0F61 26FC 2594 6BDF 8823

To claim this, I am signing this object:

/*************************************************************
* at328-0.c - Demonstrate simple I/O functions of ATmega328
*
* Program loops turning PC0 on and off as fast as possible.
*
* The program should generate code in the loop consisting of
* LOOP: SBI PORTC,0 (2 cycles)
* CBI PORTC,0 (2 cycles)
* RJMP LOOP (2 cycles)
*
struct node {
void *value;
struct node *next;
};
typedef struct node node;
void
delete_node(node **head, node *to_delete)
{
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"failed":[
],
"start":"2013-09-30T00:00:00",
"end":"2013-10-06T23:59:59",
"schedule":[
{
"task":true,
"end":"2013-09-30T18:20:00",
@gerow
gerow / hex_to_words.rb
Last active December 20, 2015 11:39
Convert a hex string into a semipronouncable string of characters
#!/usr/bin/ruby
string = ARGV[0]
puts string.downcase.split("").map{|e|
case e
when "0"
"ka"
when "1"
"ta"
when "2"
@gerow
gerow / hex_to_words.rb
Created July 31, 2013 19:39
Convert a hex string into a semipronouncable string of characters
#!/usr/bin/ruby
string = ARGV[0]
puts string.downcase.split("").map{|e|
case e
when "0"
"ka"
when "1"
"tsu"
when "2"
@gerow
gerow / gist:5903544
Created July 1, 2013 18:56
I've been using this pattern a lot in ruby, and I was wondering if there's a better way to do this. It kinda feels like its perverting the use of the reduce function when all I really want to do is split a list into a list of lists by a specific field value.
def split_list_by list, &block
list.reduce({}) {|memo, v|
key = yield v
memo[key] ||= []
memo[key] << v
memo
}.map{|k, v|
v
@gerow
gerow / map-partial-reductions.clj
Last active December 19, 2015 02:09
Looking for what this function might be called. I would call it a function that maps a list to its partial reductions.
(defn map-partial-reductions
"Given a reduce function, an initial value for the reduce, and a list generate a list of partial reductions as it goes"
[f memo l]
(reduce #(if (nil? (last %1))
(conj %1 (f memo %2))
(conj %1 (f (last %1) %2))) [] l))
; So, for the following
(map-partial-reductions + 0 '(1 2 3 4 5))
; => [1 3 6 10 15]