Skip to content

Instantly share code, notes, and snippets.

View andrewvc's full-sized avatar

Andrew Cholakian andrewvc

View GitHub Profile
@andrewvc
andrewvc / version_sort.rb
Last active December 17, 2015 21:09
Sort version number strings properly
# Turn version number into a 48 bit value (16 bits per version number) that is comparable to other versions
def rank_version(ver_str)
ver_str.
split('.').
map(&:to_i).
reduce([5*16,0]) {|acc,v| #These vars are horribly named
i,a=acc
[i - 16, a | (v << i) ]
}[1]
end
@andrewvc
andrewvc / index.haml
Created March 3, 2013 07:29
A CodePen by Andrew Cholakian.
#command-bar
%form#client
.labels
%label#ajax-method-label{for: "method"} Method
%label#server-label{for: "server"} Server
%label#path-label{for: "Path"} Path
.fields
%select#ajax-method{name: "method"}
%option{value: "GET"} GET
%option{value: "PUT"} PUT
@andrewvc
andrewvc / elastic_search_crash_course.md
Last active November 2, 2020 06:24
Elastic Search Crash Course for LA Hacker News

#elasticsearch Crash Course!

By Andrew Cholakian

What is elasticsearch?

  1. A way to search... things
  2. A way to search your data in terms of natural language, and so much more
  3. A distributed version of lucene with a JSON API.
  4. A fancy clustered database
irb(main):021:0> x = "foobar"
=> "foobar"
irb(main):022:0> x =~ /(foo)/
=> 0
irb(main):023:0> $1
=> "foo"
irb(main):024:0> Thread.new { x =~ /(bar)/; puts $1}.join
bar
=> #<Thread:0x007ff47a10cb58 dead>
irb(main):025:0> $1
@andrewvc
andrewvc / gz-reader-writer.clj
Created December 19, 2012 06:45
read and write streams with BufferedWriter and BufferedReader in Clojure
(ns something
(:import [java.io
BufferedWriter
BufferedReader
OutputStreamWriter
InputStreamReader
FileOutputStream
FileInputStream]
[java.util.zip
GZIPOutputStream
use std;
import io::println;
import io::reader_util;
type birth_row = {
prglength: int,
outcome: int,
birthord: int};
@andrewvc
andrewvc / preg_avgs_shell.sh
Created September 30, 2012 17:26
Thinking Stats first exercise, using shell instead of python
#!/bin/sh
split_cmd='cut -b 275,276,277,278,279 2002FemPreg.dat'
first_avg=`$split_cmd | grep '1 1$' | cut -b 1,2 | awk '{s += $1} END { print s/NR }'`
other_avg=`$split_cmd | grep -v ' 1$' | grep '1..$' | cut -b 1,2 | awk '{s += $1} END { print s/NR }'`
hours_diff=`echo "($first_avg-$other_avg)*168" | bc`
echo First borns: $first_avg weeks
echo Non-first borns: $other_avg weeks
echo Difference: $hours_diff hours

Noir Async!

Why?

  • Async HTTP now common, it should be easy in clojure!
  • Lamina is probably my favorite clojure lib, but it's hard to use directly
  • The existing interfaces bridging Noir and Lamina are tricky

Let's make something simple!

http://spoti.fi/Sce6qI
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAdElEQVQYV2NkYGD4D8Rg8H+3TwOIZnTdAqZRxEDyMAXIipDFwOLYFKIrIk0hUHc9zD0wq7E5hRGkENnx2DwF0gh2I7IkzHSY5q1btzZ4sU3H9AyyQpgisJOQ3YjuBLhpwHCFK4Qpgnlk269MsOHe3t7gwAcABqJUq2xpzowAAAAASUVORK5CYII=