Skip to content

Instantly share code, notes, and snippets.

@itang
itang / chan_test.go
Created December 16, 2013 09:08
go chan: nil, empty
package main
import (
"fmt"
"reflect"
)
func main() {
//var a = 1
//var p *int = &a
@itang
itang / sockets_client.go
Created December 17, 2013 08:04
go socket sample
package main
import (
"bufio"
"fmt"
"net"
)
func main() {
conn, err := net.Dial("tcp", "localhost:9002")
@itang
itang / jo.rb
Created December 18, 2013 13:35
jruby jo gem test
require 'jo'
include Jo
java_import java.lang.System
java_import java.util.Date
puts Date.new(System::currentTimeMillis)
# pinger ponger printer
@itang
itang / pg.go
Created December 23, 2013 02:22
golang + postgreSQL example
package main
import (
"database/sql"
"fmt"
"log"
// load postgres driver
_ "github.com/lib/pq"
)
@itang
itang / reverse_string.go
Last active May 26, 2018 10:06
golang: reverse string
package main
import (
"fmt"
"unicode/utf8"
)
func main() {
fmt.Println(reverse("abc"))
fmt.Println(reverse("中文"))
s = "export GOPATH=/home/itang/sources/go-projects\n"
s = s + File.readlines("/home/itang/tmp/3.g")
.select{|line| line.start_with?("Unstar")}
.map{|line| line.split(" ")[1]}
.map{|p| "go get -v github.com/#{p}"}
.join("\n")
File.open("/home/itang/tmp/3.sh", "w") do |f|
f.write(s)
end
require 'open-uri'
url = 'https://github.com/mozilla/rust/wiki/Rustpkg'
projects = open(url).read().scan(/<a .*>.*<\/a>/)
.select {|a| a.match("https://github.com/") }
.reject {|a| a.match("https://github.com/mozilla/")}
projects.each do |a|
href = a.match(/"(.*)"/)[1]
@itang
itang / rust.rb
Created December 31, 2013 13:16
Rust Launcher
#!/home/itang/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
# encoding: utf-8
# save as file "rust"
def println_info(task, file)
puts "Rust Launcher..."
puts "#{'work dir'.ljust(10)}:#{Dir.getwd}"
puts "#{'task'.ljust(10)}:#{task}"
puts "e.g.
$ ./rust run hello.rs
@itang
itang / i.rs
Created January 1, 2014 12:06
Rust Source Of An Introduction to Rust Programming Language - Rust Tutorial
fn main() {
println("Hello? yes , this is rust");
let hi = "hi";
let mut count = 0;
while count < 10 {
println(hi);
println(format!("{:s} is {:d}", hi, count));
count += 1;
@itang
itang / go-update.sh
Created January 28, 2014 05:00
go update batch
#!/bin/bash
go get -u -v github.com/codegangsta/martini
go get -u -v github.com/codegangsta/martini-contrib/...
go get -u -v github.com/robfig/revel/...