Skip to content

Instantly share code, notes, and snippets.

language = "elixir"
^language = "ruby" # raise MatchError
@kiennt
kiennt / pattern_matching_bench.exs
Created March 2, 2016 16:22
Elixir Pattern matching performance
defmodule Foo do
def cc(?0), do: 0
def cc(?1), do: 1
def cc(?2), do: 2
def cc(?3), do: 3
def cc(?4), do: 4
def cc(?5), do: 5
def cc(?6), do: 6
def cc(?7), do: 7
def cc(?8), do: 8
@kiennt
kiennt / bash_profile
Created September 15, 2013 16:09
Autoload virtual environment in bash
cd() {
builtin cd "$1"
if [ -d "venv" ] then
. venv/bin/activate
fi
}
@kiennt
kiennt / gist:6425774
Created September 3, 2013 15:53
MySQL RDS config
mysql> show status;
+------------------------------------------+---------------+
| Variable_name | Value |
+------------------------------------------+---------------+
| Aborted_clients | 3499360 |
| Aborted_connects | 3005 |
| Binlog_cache_disk_use | 52 |
| Binlog_cache_use | 15845471 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
@kiennt
kiennt / PageView.mm
Created May 16, 2013 04:22
Sample code review
//
// MyPageView.m
// AppotaApp
//
// Created by Anh Toan on 11/27/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "MyPageView.h"
#import "UserCommentView.h"
@kiennt
kiennt / Huffman.scala
Created April 29, 2013 06:45
Scala coursera Week 4
package patmat
import common._
/**
* Assignment 4: Huffman coding
*
*/
object Huffman {
@kiennt
kiennt / TweetData.scala
Created April 29, 2013 06:43
Coursera scala week 3
package objsets
// real tweet data, collected on Oct 1
object TweetData {
val gizmodo = """[
{ "user": "gizmodo", "text": "Kindle Paperwhite Review: Forget Everything Else, This Is the E-Reader You Want http://t.co/737W6aNC", "retweets": 51.0 },
{ "user": "gizmodo", "text": "These new Apple patents give a sneak peek at what future iPhone cameras might have in store. http://t.co/0YT9rjxp", "retweets": 49.0 },
{ "user": "gizmodo", "text": "Ever wonder why the sky is dark at night? Here's your answer. http://t.co/eTKxkcaE", "retweets": 86.0 },
{ "user": "gizmodo", "text": "The head of Homeland Security stays secure by just not using email, at all. http://t.co/W6KAFEUu", "retweets": 37.0 },
{ "user": "gizmodo", "text": "This is how graphene will grow the flexible semiconductors of the future: http://t.co/IoEvuxp4", "retweets": 43.0 },
class FiboUsingDictionary
include Singleton
def initialize
@fib = { 0 => 1, 1 => 1 }
end
def [](n)
return @fib[n] if @fib.include? n
@fib[n] = self[n -1] + self[n - 2]
@kiennt
kiennt / fibo_array.rb
Last active December 14, 2015 04:49
Fibonaci using array
class FiboUsingArray
include Singleton
def initialize
@fib = [1, 1]
end
def [](n)
if n < @fib.size then
@fib[n]
@kiennt
kiennt / pre-define-method-array.rb
Last active December 13, 2015 20:08
Pre define method for array sort
require 'benchmark'
Benchmark.bm do |x|
names = ["matz", "rossum", "ryal", "ritchie", "brendan"]
n = 50000
x.report "method missing" do
class Array
def method_missing name, *argv
super unless name =~ /^sort_by_(\w+)_(asc|desc)$/