Skip to content

Instantly share code, notes, and snippets.

View zh4ngx's full-sized avatar

Andy Zhang zh4ngx

  • San Francisco, CA
View GitHub Profile
@zh4ngx
zh4ngx / find_missing_number.rb
Last active December 23, 2015 23:39
Find missing number from array
def missing_number num_array:
n = num_array.length + 1
expected = n * (n + 1) / 2
actual = num_array.reduce :+
missing = expected - actual
return missing
end
Log onto bad mongo primary
Use mongotop to find bad database
Run this to find long running queries
db.currentOp()['inprog'].filter(function (t){return t.secs_running > 10}).map(function (t){return t.opid})
Kill bad ops with
db.killOp(<opid>)
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@zh4ngx
zh4ngx / _profile_preview.haml
Created September 6, 2012 19:23
CarrierWave Image Preview/Upload
.river-pics
= profile_image_for current_user
%p #{current_user.first_name}, #{current_user.age}
.blurb
%p
#content
%h1 Satisfied?
%p Hover your mouse over your picture.
%p This is how others will see you.
@zh4ngx
zh4ngx / .profile fragment
Created June 11, 2012 04:03 — forked from jcamenisch/.profile fragment
Lightning-fast project-wide find/replace with git grep and sed
gg_replace() {
if [[ "$#" == "0" ]]; then
echo 'Usage:'
echo ' gg_replace term replacement file_mask'
echo
echo 'Example:'
echo ' gg_replace cappuchino cappuccino *.html'
echo
else
find=$1; shift