Skip to content

Instantly share code, notes, and snippets.

View daqing's full-sized avatar

David Zhang daqing

View GitHub Profile
def insertion_sort(seq)
(1..seq.size - 1).each do |i|
key = seq[i]
left = i - 1
while left >= 0 and seq[left] > key
seq[left + 1] = seq[left]
seq[left] = key
left -= 1
end
" =========================
" File: daqing.vim
" Description: small plugin to asistant my day-to-day development
" Maintainer: Kinch Zhang <[email protected]>
" License: The MIT License <http://www.opensource.org/licenses/mit-license.php>
" =========================
fun! Write(str)
execute "normal I" . a:str . "\<Esc>"
endfun
import scala.actors.Actor
import scala.actors.Actor._
case object Ping
case object Pong
case object Stop
class Ping(count: Int, pong: Actor) extends Actor {
def act() {
var pingsLeft = count - 1
import scala.actors.Actor
import scala.actors.Actor._
case object Ping
case object Pong
case object Stop
class Ping(count: Int, pong: Actor) extends Actor {
def act() {
var pingsLeft = count - 1
" =========================
" File: daqing.vim
" Description: small plugin to asistant my day-to-day development
" Maintainer: Kinch Zhang <[email protected]>
" License: The MIT License <http://www.opensource.org/licenses/mit-license.php>
" =========================
fun! Write(str)
execute "normal I" . a:str . "\<Esc>"
endfun
@daqing
daqing / auto-login.sh
Created May 6, 2010 06:45
auto login different hosts using expect
#!/usr/bin/expect -f
array set d {
141 "abc"
142 "foobar"
145 "buz"
}
if { $argc != 1 } {
puts "usage: $argv0 HOST"
puts "HOST can be 195 or 201"
/**
* Basecamp stylesheet, based on "alternate"
* author: Peter Theill, Commanigy - http://com​manigy.com
*
* @2009-11-16 - fix #3069
* @2009-11-12 - styling "password" fields as well with a simple border (similar to other fields)
*
*/
@import url(../../../stylesheets/application.css);
def v2ex_api(path)
url = URI.parse("http://v2ex.appspot.com")
res = Net::HTTP.start(url.host, url.port) do |http|
http.get(path)
end
ActiveSupport::JSON.decode res.body
end
puts v2ex_api("/api/members/show.json?username=daqing").inspect
<% items = [] %>
<% ["About", "FAQ", "Mission", "Blog", "Advertise"].each do |page| %>
<% items << %(<strong>#{link_to t(page.downcase.to_sym), '/page/#{page.downcase}', :class => :dark}</strong>) %>
<% end %>
<%=raw items.join('&nbsp; | &nbsp;') %>
@daqing
daqing / MetaTest.rb
Created April 22, 2011 06:04
understanding-class_eval-instance_eval-and-define_method
class Test
class_eval <<-END
def self.a
puts "a"
end
END
instance_eval <<-END
def b
puts "b"