Skip to content

Instantly share code, notes, and snippets.

@chensoren
chensoren / gist:1220991
Created September 16, 2011 01:48
execute action after specify time
loadCmdStatus = function() {
$.getJSON('/command/9857438925794/status', function(cmdReq) {
var now = new Date();
beginTime = now.getTime();
if (cmdReq.executed == '1' || cmdReq.executed == '0' || cmdReq.executed == '-1') {
} else {
}
@chensoren
chensoren / gist:1375314
Created November 18, 2011 01:58
Rake task with arguments and :environment
desc "Rake task with arguments and :environment"
task :task_name, [:arg1, :arg2] => :environment do |t, args|
args.with_defaults(:arg1 => "Foo", :arg2 => "Bar")
puts "Hello, #{args.arg1}. Bye, #{args.arg2}."
end
@chensoren
chensoren / gist:1872631
Created February 21, 2012 00:51
Embed Ext.list inside Ext.Panel component
Ext.define('Program', {
extend: 'Ext.Panel',
id: 'program',
xtype: 'programview',
fullscreen: true,
config: {
layout: 'fit',
items: [
{xtype:'titlebar',
docked: 'top',
@chensoren
chensoren / gist:1873512
Created February 21, 2012 03:50
align component center inside Ext.Panel
app.views.Signature=Ext.extend(Ext.Panel,{
layout:{
type:'vbox',
pack: 'start',
align: 'center'
}
});
@chensoren
chensoren / NokogiriXPathNamespaces
Created April 16, 2012 06:59 — forked from Ameeda/NokogiriXPathNamespaces
Selecting elements in some namespace using Nokogiri with XPath
2 ways to extract elements from within XML namespaces using Nokogiri
When trying to select elemenets in the default namespace, e.g. "xmlns= http://www.w3.org/2005/Atom", try the following two ways. Note the xmlns=" attribute on entry element:
Original xml:
Nokogiri::XML(@xml_string).xpath("//author/name").each do |node|
puts node
end
1. Define a namespace context for your XPath expression and point your XPath steps to match elements in that namespace. Define a namespace-to-prefix mapping and use this prefix (a) in the XPath expression.
@chensoren
chensoren / gist:2652351
Created May 10, 2012 10:34
start a tcp client and server by eventmachine(two connection)
require 'rubygems'
require 'eventmachine'
require "socket"
module GwServer
# @server_socket = TCPSocket.open('127.0.0.1', 3000)
class GwTcpClient < EventMachine::Connection
@chensoren
chensoren / gist:2656869
Created May 11, 2012 01:04
receive data from one client and forward data to tcp server on remote
require 'rubygems'
require 'eventmachine'
require "socket"
module GwServer
# @server_socket = TCPSocket.open('127.0.0.1', 3000)
# @queue = []
class GwTcpClient < EventMachine::Connection
@chensoren
chensoren / gist:3023062
Created June 30, 2012 09:16
bash_profile
# terminal color setting
#terminal color setting
export TERM=xterm-color
export CLICOLOR=1
export LSCOLORS=gxfxaxdxcxegedabagacad
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# color the ls output
alias ls='ls -G'
# shortcut for detailed listing
@chensoren
chensoren / tls-cert-generator.rb
Created July 9, 2012 03:23 — forked from ibc/tls-cert-generator.rb
Autosigned TLS Certificate Generator (including SubjectAltName fields for "URI:sip" and "DNS")
#!/usr/bin/ruby
# Runs as follows:
#
# ~$ ruby tls-cert-generator.rb
require "openssl"
require "socket"
@chensoren
chensoren / gist:3081968
Created July 10, 2012 08:10
ruby openssl AES encrypt and decrypt
require 'base64'
require 'digest'
require 'openssl'
module AESCrypt
def AESCrypt.encrypt(password, iv, cleardata)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt # set cipher to be encryption mode
cipher.key = password