Skip to content

Instantly share code, notes, and snippets.

View newtonapple's full-sized avatar

David Dai newtonapple

  • Tobiko Data
  • San Francisco
View GitHub Profile
@newtonapple
newtonapple / interleaver_array.rb
Last active June 22, 2021 21:26
Ruby Interleaver
# frozen_string_literal: true
require "zlib"
require 'set'
class InterleaverArray
TEAM_A_NAME = "A"
TEAM_B_NAME = "B"
attr_accessor :a, :b, :a_index, :b_index, :a_size, :b_size
@newtonapple
newtonapple / RankingDistances.ipynb
Created April 2, 2018 05:58 — forked from pilipolio/RankingDistances.ipynb
Experiments based on paper "Generalized distances between rankings" by Kumar and Vassilvitskii.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@newtonapple
newtonapple / job_control_zsh_bash.md
Created July 14, 2016 17:41 — forked from CMCDragonkai/job_control_zsh_bash.md
CLI: Job Control in ZSH and Bash

Job Control in ZSH and Bash

All processes in ZSH/Bash under job control are in 3 states: foregrounded, backgrounded and suspended.

# run command in the foreground
command
# run commend in the background
@newtonapple
newtonapple / bench_10000_1000000.rb
Last active August 29, 2015 14:21
Roshi Benchmarks on local iMac with default local settings (GOMAXPROCS=1)
require './gen'
gen(10000, 1_000_000)
puts "generated data for: 10,000 users, 1 million events, 100 events per user."
puts "\ncurl -Ss -d@insert.json -XPOST 'http://localhost:6302' | jq ."
puts `curl -Ss -d@insert.json -XPOST 'http://localhost:6302' | jq .`
# note it will pass 10,000 user_ids on every select
puts "\ncurl -Ss -d@select.json -XGET 'http://localhost:6302?coalesce=true&limit=20' | jq . | grep duration"
┌──────────────────────────────────────────────┐ ┌──────────────────────────────────────────────┐
│ │ │ │
│ Select Library ▼ Q ▕▽ │ │ Select Library ▼ Q ▕▽ │
│ │ │ │
├──────────────────────────────────────────────┤ ├──────────────────────────────────────────────┤
│ TO READ ▕ READING ▕ FINISHED ▕ ALL │ │ ALL ▕ TO READ ▕ READING ▕FINISHED │
├──────────────────────────────────────────────┤ ├──────────────────────────────────────────────┤
│ Nov 2014 All Genres │ │ Nov 2014 All Genres │
├──────────────────────────────────────────────┤ ├──────────────────────────────────────────────┤
@newtonapple
newtonapple / gist:fb3de3b32b7039a85479
Last active January 18, 2017 04:30
Elasticsearch Notes

Elasticsearch runs on:

doc-search01.lo:19200

Create or update a record

curl -XPUT  "doc-search01.lo:19200/megacorp/employee/5" -d '
{

"first_name" : "Jane",

class Simhash
attr_reader :weights, :bits_length, :bitmasks
def initialize(bits_length=64)
@bits_length = bits_length
@weights = Array.new(@bits_length, 0.0)
@bitmasks = Array.new(@bits_length)
(0...@bits_length).each do |i|
@bitmasks[i] = (1 << i)
end
end
@newtonapple
newtonapple / gist:4122198
Created November 21, 2012 00:15
Campfire emoji bomb.
:+1: :-1: :8ball: :a: :ab: :airplane: :alien: :ambulance: :angel: :anger: :angry: :apple: :aquarius: :aries: :arrow_backward: :arrow_down: :arrow_forward: :arrow_left: :arrow_lower_left: :arrow_lower_right: :arrow_right: :arrow_up: :arrow_upper_left: :arrow_upper_right: :art: :astonished: :atm: :b: :baby: :baby_chick: :baby_symbol: :balloon: :bamboo: :bank: :barber: :baseball: :basketball: :bath: :bear: :beer: :beers: :beginner: :bell: :bento: :bike: :bikini: :bird: :birthday: :black_square: :blue_car: :blue_heart: :blush: :boar: :boat: :bomb: :book: :boot: :bouquet: :bow: :bowtie: :boy: :bread: :briefcase: :broken_heart: :bug: :bulb: :bullettrain_front: :bullettrain_side: :bus: :busstop: :cactus: :cake: :calling: :camel: :camera: :cancer: :capricorn: :car: :cat: :cd: :chart: :checkered_flag: :cherry_blossom: :chicken: :christmas_tree: :church: :cinema: :city_sunrise: :city_sunset: :clap: :clapper: :clock1: :clock10: :clock11: :clock12: :clock2: :clock3: :clock4: :clock5: :clock6: :clock7: :clock8: :clock9: :
@newtonapple
newtonapple / Facebook User Agent
Created July 10, 2012 20:47
FB & Twitter iPhone browser user agent.
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en_US) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.1.1;FBBV/4110.0;FBDV/iPhone3,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/5.1.1;FBSS/2; FBCR/AT&T;FBID/phone;FBLC/en_US;FBSF/2.0]
@newtonapple
newtonapple / keyframe.css
Created April 25, 2012 09:24
CSS Keyframe Animation Syntax
/*
References:
http://css-tricks.com/snippets/css/webkit-keyframe-animation-syntax/
https://developer.mozilla.org/en/css/css_animations
Compatible with Firefox 5+, IE 10+, Chrome 6+, Safari 5+
*/
/* Declaration (add appropriate browser prefix accordinginly) */
@-webkit-keyframes animation-name {