Skip to content

Instantly share code, notes, and snippets.

View daqing's full-sized avatar

David Zhang daqing

View GitHub Profile
@daqing
daqing / first-echo-server.c
Created September 18, 2011 06:29
my first forking echo server
#include <stdio.h>
#include <stdlib.h> // for exit
#include <sys/socket.h> // for socket
#include <sys/types.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>
#include <sys/wait.h>
@daqing
daqing / hello-world-socket.c
Created September 18, 2011 03:50
my first 'hello world' example for socket programming
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>
#include <sys/wait.h>
@daqing
daqing / meta.rb
Created May 6, 2011 02:07
Ruby Meta Programming Explained
class Class
def where
"in class Class"
end
end
person = Class.new
puts "person.where: #{person.where}" # => "in class Class"
class << person
@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"
<% 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;') %>
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
/**
* 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);
@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"
" =========================
" File: daqing.vim
" Description: small plugin to asistant my day-to-day development
" Maintainer: Kinch Zhang <kinch.zhang@gmail.com>
" 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