Skip to content

Instantly share code, notes, and snippets.

View goshacmd's full-sized avatar

Gosha Spark goshacmd

View GitHub Profile
@goshacmd
goshacmd / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
require 'free_will'
class Calculator
# you don't want your calculator to love you and serve you blindly
# you don't want it to be like a programmed robot
# instead, you want it to have free will...
include FreeWill
def add(n1, n2)
n1 + n2

Keybase proof

I hereby claim:

  • I am goshakkk on github.
  • I am goshakkk (https://keybase.io/goshakkk) on keybase.
  • I have a public key whose fingerprint is 6A4A F3BA 3D88 0796 D23E 9168 4ADC CD51 1740 FB0C

To claim this, I am signing this object:

@goshacmd
goshacmd / bitcoin.js
Created October 14, 2013 14:58
Bitcoin.js bower package
/**
* BitcoinJS-lib v0.1.3-default
* Copyright (c) 2011 BitcoinJS Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the MIT license.
*/
(function(){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=window.Crypto={},n=t.util={rotl:function(e,t){return e<<t|e>>>32-t},rotr:function(e,t){return e<<32-t|e>>>t},endian:function(e){if(e.constructor==Number)return n.rotl(e,8)&16711935|n.rotl(e,24)&4278255360;for(var t=0;t<e.length;t++)e[t]=n.endian(e[t]);return e},randomBytes:function(e){for(var t=[];e>0;e--)t.push(Math.floor(Math.random()*256));return t},bytesToWords:function(e){for(var t=[],n=0,r=0;n<e.length;n++,r+=8)t[r>>>5]|=e[n]<<24-r%32;return t},wordsToBytes:function(e){for(var t=[],n=0;n<e.length*32;n+=8)t.push(e[n>>>5]>>>24-n%32&255);return t},bytesToHex:function(e){for(var t=[],n=0;n<e.length;n++)t.push((e[n]>>>4).toString(16)),t.push((e[n]&15).toString(16));return t.join("")},hexToBytes:function(e){for(var t=[],n=0;n<e.l
@goshacmd
goshacmd / fix_sys_rb.sh
Created June 12, 2013 07:41
OS X [REDACTED] Ruby 2.0 headers fix.
sys_rb_usr=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr
sdk_rb_usr=`xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr
sudo cp -r $sdk_rb_usr/include $sys_rb_usr/include
$ cat bm.rb
require './env'
Benchmark.bm do |x|
x.report('block') { OrderEvent.all.limit(100_000).map(&:total) }
x.report('sym') { OrderEvent.all.limit(100_000).map(:total) }
end
$ ruby bm.rb
user system total real
@goshacmd
goshacmd / bm.txt
Created January 20, 2013 20:01
MongoDB: Map/Reduce vs Aggregation framework on 1M docs. Basically just counting how many times was made each request (only 250K of requests had search queries). Aggregation turned to be 84x faster.
1000000 documents
249819 documents with non-empty 'search_query'
user system total real
simple map/reduce 0.270000 0.010000 0.280000 (353.701946)
simple aggregation 0.180000 0.010000 0.190000 ( 8.049170)
filtering map/reduce 0.250000 0.010000 0.260000 (337.955130)
filtering aggregation 0.150000 0.010000 0.160000 ( 4.095468)
@goshacmd
goshacmd / inline_relations.rb
Created January 16, 2013 19:58
Mongoid inline relation definitions. Ruby makes it so easy ❤️
# Mongoid inline relation definitions. Ruby makes it so easy.
# (`data` is effectively just a shortcut for `inline_embed_one(:data)` there.)
#
# Yes, it would make sense to create separate models, but my case is different.
# This application is used to track events of other apps, such as purchase, and
# it makes *more* sense to embed all order-related data. Instead of having model
# overload for each event being tracked, I just define them inline.
class OrderEvent
include Analyzing::Event
@goshacmd
goshacmd / README.md
Created January 7, 2013 17:05
Rails-generated app README idea

AppName

Insert brief description of your app.

Requirements

  • Ruby 1.9.3+
  • Bundler 1.3.0
  • PostgreSQL