Skip to content

Instantly share code, notes, and snippets.

View tancnle's full-sized avatar
🌸
Living The Dream ᕙ༼*◕_◕*༽ᕤ

Tan Le tancnle

🌸
Living The Dream ᕙ༼*◕_◕*༽ᕤ
View GitHub Profile
@tancnle
tancnle / date_time_parser.rb
Created August 12, 2013 03:57
Date time parser
\A(\d{4})(-?)(\d{2})\2(\d{2})(?:[T\s-](\d{2})(:?)(\d{2})(?:\6(\d{2}))?)?\z
@tancnle
tancnle / setup_mosh_centos.sh
Last active December 5, 2019 03:01
Setup mosh on Centos 6.x
#!/bin/sh
# Update latest epel
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6-8.noarch.rpm
# Download and build mosh
sudo yum -y install rpm-build rpmdevtools protobuf-compiler protobuf-devel libutempter-devel zlib-devel ncurses-devel openssh-clients perl-IO-Tty openssl-devel gcc gcc-c++
rpmdev-setuptree
cd ~/rpmbuild/SOURCES
@tancnle
tancnle / setup_ack.md
Created January 31, 2014 11:52
Setup ack on MacOSX
$ brew install ack
$ ack --version

Create ~/.ackrc (Below is my ackrc example, modify as you see fit)

# Options
--smart-case
--sort-files

Exclusions

@tancnle
tancnle / sort_vs_sort_by.rb
Created March 12, 2014 22:26
sort vs sort_by for intensive operation
require 'benchmark'
root_directories = Dir.glob("/*")
n = 5000
Benchmark.bm do |x|
x.report("sort") do
n.times{ root_directories.sort { |a, b| File.ctime(a) <=> File.ctime(b) } }
end
@tancnle
tancnle / index.html
Created October 14, 2014 10:35
Angular controller calling multiple services (http://jsbin.com/zuvuwabolovu/7)
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app='testScope'>
<div ng-controller='BankController'>
<div transaction>
@tancnle
tancnle / ForExpressionExplain.scala
Created March 24, 2015 00:33
Scala For Expressions
case class Mascot(name: String)
case class SportTeam(mascot: Mascot)
case class City(sportTeams: List[SportTeam])
case class State(cities: List[City])
case class Country(states: List[State])
def getAllMascots(country: Country): List[Mascot] = {
for {
states <- country.states
cities <- states.cities
@tancnle
tancnle / roman_numerals.rb
Last active August 29, 2015 14:22
Convert arabic to roman numerals
def possible_reps(input)
lambda {|k,_| k <= input}
end
def build_roman(input)
lambda do |result, (arabic, roman)|
if (input >= arabic)
quotient, input = input.divmod(arabic)
result << roman*quotient
end
@tancnle
tancnle / saddle_points.rb
Created July 2, 2015 04:09
Find saddle points from given matrix
require 'matrix'
matrix = Matrix[
[9, 2, 8, 6],
[5, 3, 1, 5],
[6, 8, 7, 9]
]
cols = matrix.column_vectors
rows = matrix.row_vectors
@tancnle
tancnle / kindergarten_garden.rb
Created July 2, 2015 04:12
Allocate plans to students
require 'matrix'
cups_per_student_per_row = 2
plants = %w( G C R V )
students = %w( Alice Bob Charlie David Eve Fred Ginny Harriet Ileana Joseph Kincaid Larry ).sort
layout = Matrix[
24.times.map{ plants.sample },
24.times.map{ plants.sample }
]
@tancnle
tancnle / html5_speech.js
Last active August 29, 2015 14:24
Make your browser speak
var say = function(msg) {
var speech = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
speech.voice = voices[10]; // 'en-AU' 'Karen'
speech.text = msg;
speech.onend = function(e) {
console.log('Finished in ' + event.elapsedTime + ' seconds.');
};