Skip to content

Instantly share code, notes, and snippets.

View yuanfeiz's full-sized avatar

YuanfΞi Zhu yuanfeiz

  • The Homestead Arcology
View GitHub Profile
@yuanfeiz
yuanfeiz / hex_color.to_a
Created December 7, 2011 08:31
color(hex) => color(rgb array)
"101aff".scan(/../).map {|color| color.to_i(16)}
@yuanfeiz
yuanfeiz / gist:1464992
Created December 12, 2011 04:50
recrusive remove .svn directories
find ./ -name ".svn" | xargs rm -Rf
@yuanfeiz
yuanfeiz / rm_duplicates.sh
Created January 8, 2012 07:26
remove duplications in osx
OUTF=rem-duplicates.sh; echo "#! /bin/sh" > $OUTF; find . "$@" -type f -print0 | xargs -0 -n1 gmd5sum | sort --key=1,32 | guniq -w 32 -d --all-repeated=separate | gsed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF; chmod a+x $OUTF; ls -l $OUTF
@yuanfeiz
yuanfeiz / xunlei_cloudplayer.js
Created January 9, 2012 16:22
unlimited cloudplayer
javascript:void((function(){var e=document.createElement('script');e.setAttribute('src','http://xlxx.sinaapp.com/xlvod.js');document.body.appendChild(e);})())
@yuanfeiz
yuanfeiz / xunlei_cloudplayer.js
Created January 9, 2012 16:22
unlimited cloudplayer
javascript:void((function(){var e=document.createElement('script');e.setAttribute('src','http://xlxx.sinaapp.com/xlvod.js');document.body.appendChild(e);})())
@yuanfeiz
yuanfeiz / dropShadow.m
Created February 24, 2012 07:39
drop shadow of text in obj-c
- (void) drawTextInRect:(CGRect)rect {
CGSize myShadowOffset = CGSizeMake(0, 0);
float myColorValues[] = {0, 0, 0, .8};
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(myContext);
CGColorSpaceRef myColorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef myColor = CGColorCreate(myColorSpace, myColorValues);
CGContextSetShadowWithColor (myContext, myShadowOffset, 2, myColor);
@yuanfeiz
yuanfeiz / database_commands.sh
Created March 5, 2012 06:25
snippets for database imports and exports.
# Copy/Export a Large Database
mysqldump -u [USERNAME] -p [DBNAME] | gzip > [/path_to_file/DBNAME].sql.gz
#################################################################################
# Import a Large Database
gzip -d [/path_to_file/DBNAME].sql.gz
[/path_to_mysql/]mysql -u [USERNAME] -p
# DO THE FOLLOWING
@yuanfeiz
yuanfeiz / map.js.coffee
Created April 1, 2012 19:01
GoogleMaps with RichMarkers
class Map
constructor: (@el, @collection, template = "", @shadow = "") ->
@options =
zoom: 13
mapTypeId: google.maps.MapTypeId.ROADMAP
@map = new google.maps.Map @el, @options
@setTemplate template
setTemplate: (template)->
@yuanfeiz
yuanfeiz / upload.rb
Created April 5, 2012 09:11
sinatra upload file
require 'sinatra'
post '/upload' do
unless params[:file] &&
(tmpfile = params[:file][:tempfile]) &&
(name = params[:file][:filename])
@error = "No file selected"
return haml(:upload)
end
STDERR.puts "Uploading file, original name #{name.inspect}"
%form{:action=>"/upload",:method=>"post",:enctype=>"multipart/form-data"}
%input{:type=>"file",:name=>"file"}
%input{:type=>"submit",:value=>"Upload"}