Skip to content

Instantly share code, notes, and snippets.

View xingxing's full-sized avatar
🎧
Focusing

Wade Ying Xing xingxing

🎧
Focusing
View GitHub Profile
# require 'monkey-proof'
#
# class Foo
# def foo() puts 'foo'; end
# end
# monkey_proof Foo
#
# class Foo
# include Enumerable
# end
%% To demonstrate tail recursion in Erlang
-module (tailrecursion).
-export ([fact/1, qsort/1, loop/0]).
%% Factorial
fact(N) -> fact(N, 1).
fact(0, A) -> 1*A;
fact(N, A) -> fact(N-1, N*A).
% Quick sort
-module (recursion).
-export ([qsort/1]).
qsort([]) -> [];
qsort([Pivot|T]) ->
qsort([X || X <- T, X < Pivot])
++ [Pivot] ++
qsort([X || X <- T, X >= Pivot]).
@yuya-takeyama
yuya-takeyama / binarytree.rb
Created February 5, 2011 14:32
Binary Tree implemented in Ruby.
module BinaryTree
class Node
attr_reader :word, :count, :left, :right
include Enumerable
def initialize(word)
@word, @count = word, 1
end
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@perusio
perusio / gist:1326701
Created October 31, 2011 01:28
Mobile device detection in Nginx with just 7 lines of configuration
### Testing if the client is a mobile or a desktop.
### The selection is based on the usual UA strings for desktop browsers.
## Testing a user agent using a method that reverts the logic of the
## UA detection. Inspired by notnotmobile.appspot.com.
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
@tsabat
tsabat / zsh.md
Last active July 7, 2024 16:56
Getting oh-my-zsh to work in Ubuntu
@Jaskirat
Jaskirat / insertion-sort.clj
Created March 10, 2012 20:54
Insertion sort in clojure
(defn insert [l k]
"Function to do insert in sorted order"
(concat (filter #(< % k) l) [k] (filter #(> % k) l)))
(defn isort [l]
"Insertion sort"
(loop [r []
l l]
(if (empty? l)
r
@takehiko
takehiko / url-quote-utf8.el
Created December 7, 2012 20:12
URL encoding with Emacs
;; 領域を選択して M-x url-quote-region-utf8 で," => URLエンコード文字列" を
;; 挿入します.UTF-8 でエンコードします.
;; また直後に C-x C-x や C-w などとすると,URLエンコード文字列に対する
;; 領域処理となります.
;; Thanks: https://gist.github.com/436913
;; もし (load "htmlutils") をしていなければ
;; 以下のコメントを外してください.
;(defun url-escape-point (c)
@10nin
10nin / Crypto.ex
Created June 5, 2013 11:52
Get MD5 message digest by elixir-lang.
defmodule Crypto do
def md5(s) do
list_to_binary(Enum.map(bitstring_to_list(:crypto.md5(s)), fn(x) -> integer_to_binary(x, 16) end))
end
end