Skip to content

Instantly share code, notes, and snippets.

View yorzi's full-sized avatar
🏠
Working from home

Andy Wang yorzi

🏠
Working from home
  • Xi'an, China
  • 23:06 (UTC +08:00)
View GitHub Profile
@yorzi
yorzi / note_001_distance_of_time_in_words.rb
Created March 18, 2011 12:39
Reports the approximate distance in time between two Time or Date objects or integers as seconds
We couldn’t find that file to show.
@yorzi
yorzi / ajax_paginate.js
Created March 23, 2011 06:17
ajax_paginate with jQuery and will_paginate gem
$(document).ready(function() {
$('.pagination a').live('click',function (){
$.getScript(this.href);
return false;
});
});
@yorzi
yorzi / git-config-for-multi-repos
Created March 24, 2011 14:06
set git config for sharing same git repos with multi-repos.
For doing push/pull as below:
git pull unfuddle master
git pull heroku master
git push unfuddle master
git push heroku master
==========================
vim .git/config
==========================
[core]
@yorzi
yorzi / api_key_generator.rb
Created March 29, 2011 03:03
api key(or any other kind of key) generator via ruby.
class KeyGenerator
require "digest/sha1"
def self.generate(length = 10)
Digest::SHA1.hexdigest(Time.now.to_s + rand(12341234).to_s)[1..length]
end
end
@yorzi
yorzi / grape_api_sample.rb
Created March 29, 2011 12:33
a well documented ruby api based on GrapeAPI.
require 'grape'
module My
class API < Grape::API
prefix 'api'
## params key list
#################################################################################################################
# 1. login
# 2. sign
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="375" id="FlvPlayer" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="true" />
<param name="movie" value="http://flvplayer.com/free-flv-player/FlvPlayer.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="FFFFFF" />
<param name="FlashVars" value="flvpFolderLocation=http://flvplayer.com/free-flv-player/flvplayer/&flvpVideoSource=http://andy.local:3000/video/safeway_screencast.flv&flvpWidth=400&flvpHeight=375&flvpInitVolume=50&flvpTurnOnCorners=true&flvpBgColor=FFFFFF"
<embed src="http://flvplayer.com/free-flv-player/FlvPlayer.swf" flashvars="flvpFolderLocation=http://flvplayer.com/free-flv-player/flvplayer/&flvpVideoSource=http://andy.local:3000/video/safeway_screencast.flv&flvpWidth=400&flvpHeight=375&flvpInitVolume=50&flvpTurnOnCorners=true&flvpBgColor=FFFF
$ screen -ls
There is a screen on:
4491.pts-2.FC547 (Attached)
1 Socket in /var/run/screen/S-sathiya.
$ screen -r 4491.pts-2.FC547
[4491.pts-2.FC547 detached.]
Just run below command to solve it.
git config core.autocrlf false
@yorzi
yorzi / rspec-syntax-cheat-sheet.rb
Created May 9, 2011 11:49 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@yorzi
yorzi / export_to_csv.rb
Last active September 25, 2015 19:38
render csv sample action
def export_to_csv
@users = User.find(:all)
csv_string = CSV.generate do |csv|
# header row
csv << ["id", "first_name", "last_name"]
# data rows
@users.each do |user|
csv << [user.id, user.first_name, user.last_name]
end