Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View danielnc's full-sized avatar

Daniel Naves de Carvalho danielnc

View GitHub Profile

Keybase proof

I hereby claim:

  • I am danielnc on github.
  • I am danielnc (https://keybase.io/danielnc) on keybase.
  • I have a public key whose fingerprint is F822 829F 701F 69C5 DBF0 1C73 73CA C4D6 FC57 89E6

To claim this, I am signing this object:

Verifying myself: My Bitcoin username is +danielnc. https://onename.io/danielnc
if defined?(ActiveRecord::Base)
module AttrEncrypted
module Adapters
module ActiveRecord
protected
class EncryptedAttributeClassWrapper
attr_reader :klass
def initialize(klass); @klass = klass; end
end
@danielnc
danielnc / convert_number_to_base.rb
Created October 25, 2013 20:58
Stupid and un-optimized converter to other numerical bases(NUMBER.to_s(base))
def convert(number, base=10)
raise "base must be between 2 and 36" if base < 2 || base > 36
negative = number < 0
number = number.abs
number_array = []
loop do
number_array.unshift("0123456789abcdefghijklmnopqrstuvwxyz"[number % base])
number /= base
break if number == 0
end
@danielnc
danielnc / extract_mongo_id.sh
Created December 14, 2012 19:00
Parsers mongo ids to Dates
cat users.in | cut -f1 | ruby -e "ARGF.each_line { |line|puts Time.at(line[0...8].to_i(16)).strftime(\"%Y%m%d\") }" | sort -r | uniq -c
@danielnc
danielnc / StreamingStats.rb
Created December 6, 2012 18:37
Stats for streaming values(mean,variance, standard_deviation)
# Check: http://www.johndcook.com/standard_deviation.html
module OmniRPC
module Util
class StreamingStats
attr_reader :min, :max
def initialize
@m_n = 0.0
@max = -Float::INFINITY
@min = Float::INFINITY
@danielnc
danielnc / humanize.rb
Last active October 13, 2015 03:28
humanize milliseconds (ruby)
def humanize(milliseconds)
[[1000, :milliseconds], [60, :seconds], [60, :minutes], [24, :hours], [365, :days], [+1.0/0.0, :years]].inject([]){ |m, (count, name)|
if milliseconds > 0
milliseconds, n = milliseconds.divmod(count)
m.unshift "#{n.to_i} #{name}"
end
m
}.join(' ')
end
@danielnc
danielnc / gist:4030943
Created November 7, 2012 11:23
log lines per second
tail -f file.log |perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}'
@danielnc
danielnc / gist:4030891
Created November 7, 2012 11:09
Bash COUNT && Percent
grep "XXXXXXX" file.log | cut -d"," -f5 | sort | awk '{a[$0]++} END{for (i in a) if (a[i]>1) printf "%10d\t%5.2f%%\t%s\n", a[i], 100*a[i]/NR, i}' | sort -rn
@danielnc
danielnc / build_atlas.sh
Created October 31, 2012 12:59 — forked from gerigk/build_atlas.sh
Build ATLAS for EC2
# UPDATE to Get the latest versions
wget http://www.netlib.org/lapack/lapack-3.4.2.tgz
wget http://sourceforge.net/projects/math-atlas/files/Stable/3.10.0/atlas3.10.0.tar.bz2/download?use_mirror=ufpr
tar -vxf atlas3.10.0.tar.bz2
cd ATLAS
mkdir build
cd build
################################## -t 8 means 8 threads. depending on the ec2 instance you can choose more threads
### V 448 means SSE1/2/3 support. A14 means x86SSE364SSE2 architecture. check the documentation for more information
### if you run smaller instances you may get 32 bit machines. in this case you need to build -b 32, too and install the