This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Cellular where | |
import System.Random | |
import Data.List.Split | |
import Data.Maybe | |
isWall False = '.' | |
isWall True = '#' | |
mapWithIndex :: (Enum a, Num a) => (a -> b -> c) -> [b] -> [c] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": ["bar"]}' | |
{"ok":true,"_index":"myindex","_type":"mytype","_id":"YYfPUL3TQLaL17zhXQ-ELw","_version":1} | |
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": [{"foo": "bar"}]}' | |
{"error":"MapperParsingException[Failed to parse [foo]]; nested: ElasticSearchIllegalArgumentException[unknown property [foo]]; ","status":400} | |
$ curl -XDELETE http://localhost:9200/myindex/mytype | |
{"ok":true} | |
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": [{"foo": "bar"}]}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def case_wat | |
case number = 1 | |
when number == 1 | |
'expected' | |
else | |
'wat' | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_value(key, hash) | |
result = hash | |
key.split('.').each do |segment| | |
segment = segment.to_i if segment =~ /\d+/ | |
result = result[segment] | |
return unless result | |
end | |
result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save_and_open_page | |
File.write('tmp/last_response.html', last_response.body) | |
`open tmp/last_response.html` | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> connection = PGconn.new(...) | |
>> connection.exec('update foo set bar=true') # long running query | |
^C^C^C^C^C^C | |
# Can't cancel the query | |
>> connection.async_exec('update foo set bar=true') # long running query | |
^C | |
>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
int main () | |
{ | |
pid_t child_pid; | |
child_pid = fork (); | |
if (child_pid > 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT datname, procpid, usename, client_addr, current_query, (current_timestamp - query_start) AS duration | |
FROM pg_stat_activity | |
WHERE datname = 'your-database' | |
ORDER BY duration DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdvancingTimeRange | |
def initialize(time = '2009-03-01') | |
@cursor = DateTime.parse(time) | |
end | |
def next(increment_by) | |
range = @cursor..@cursor + increment_by | |
@cursor = range.end | |
range | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#while true; end | |
file = File.new('/Users/akahn/out', 'w') | |
loop do | |
begin | |
buf = "" | |
buf << STDIN.read_nonblock(1024) | |
if buf =~ /^.*?\n/ | |
file.write_nonblock(buf) | |
end |