Skip to content

Instantly share code, notes, and snippets.

View luikore's full-sized avatar

luikore luikore

View GitHub Profile
@luikore
luikore / gist:895967
Created March 31, 2011 07:36
encrypt
alias base64="openssl base64"
alias aes="openssl aes-256-cbc"
@luikore
luikore / pager.rb
Created March 30, 2011 12:30
pagination with grouped index, just proof of concept, should use uuid instead of mutex
require "mongo"
class Pager
db = Mongo::Connection.new.db 'pager'
DOCS = db.collection 'docs'
INDEX = db.collection 'index'
STATE = db.collection 'state'
THRESHOLD = 1000
STATE_LOCK = Mutex.new
@luikore
luikore / sniff_ssl.rb
Created March 25, 2011 05:22
inspect http connect request
require "eventmachine"
module SSLHandler
# an SSLHandler is created for every request
def initialize
@state = :head
end
def receive_data data
case @state
@luikore
luikore / bash prompt
Created March 25, 2011 04:13
lambda-like bash prompt with git / rvm hints
# mac port installs bash_completion in /opt/local
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
# *
export GIT_PS1_SHOWDIRTYSTATE=1
# $
export GIT_PS1_SHOWSTASHSTATE=1
# %
# export GIT_PS1_SHOWUNTRACKEDFILES=1
export PS1='\[\e[32m\]λ \w\[\e[36m\]$(__git_ps1 " (%s)") [$(~/.rvm/bin/rvm-prompt i v)]\[\e[0m\]\n\[\e[32m\]→\[\e[0m\] '
@luikore
luikore / 1.part.md
Created March 17, 2011 08:56
runt unit/functional test of current file and output html for textmate

Playing with TextMate is fun, but I can't find any bundle that can make running a single-file unit test or functional test easily.

Effect

So I want to custom a command:

  • By pressing key, TextMate will figure out which test to run.

    When the opened file is app/controllers/abc_controller.rb, the test file is test/functional/abc_controller_test.rb

@luikore
luikore / rsec is faster than parsec!
Created December 30, 2010 06:46
rsec is faster than parsec
user system total real
rsec result: 32918.38
0.109000 0.000000 0.109000 ( 0.107006)
rsec rpn: 32918.38
0.140000 0.000000 0.140000 ( 0.154009)
treetop result: 32918.38
1.638000 0.000000 1.638000 ( 1.638094)
@luikore
luikore / hex_string.rb
Created December 26, 2010 04:33
hex string to bytes and codepoint
"\xae\xd3\x8f"
['AED38F'].pack('H*')
"\u4e2d"
['4e2d'].pack('H*').force_encoding('utf-16be').encode!('gbk')
@luikore
luikore / markup.rb
Created December 14, 2010 08:16
fix t.text == nil for Chinese source file. arround gems/gems/rdoc-2.5.11/lib/rdoc/generator/markup.rb:96
require 'rdoc/text'
require 'rdoc/code_objects'
require 'rdoc/generator'
require 'rdoc/markup/to_html_crossref'
##
# Handle common RDoc::Markup tasks for various CodeObjects
module RDoc::Generator::Markup
@luikore
luikore / fun.rb
Last active September 24, 2015 10:57
functional synopsis
# mixing imperative and functional code
sum = 0
(1..10).map do |i|
sum += i
end
@luikore
luikore / aes128.rb
Created November 2, 2010 18:28
AES128 in Ruby 1.9.2
# coding: utf-8
# Short code to explain the AES128 (Rijndael) cipher
# Some array operations require Ruby 1.9.2+
# Steps defined by http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
class AES128
# Mix Rows coefficients
MIX = [
[2, 3, 1, 1],