View gist:56228e0f4b86a1a115d6
1 2 3 4 5 6 7 8 9 10
class FixedPrecisionDecimal
{
const int number; // 1234.5678
 
FixedPrecisionDecimal(float)
{
 
}
FixedPrecisionDecimal(double)
{
View gist:f85198ca6dd850a2b1be
1 2 3 4 5 6 7 8 9 10
func Kermit(byteArray []byte) uint16 {
var crc uint16
for i := 0; i < len(byteArray); i++ {
b := uint16(byteArray[i])
q := (crc ^ b) & 0x0f
crc = (crc >> 4) ^ (q * 0x1081)
q = (crc ^ (b >> 4)) & 0xf
crc = (crc >> 4) ^ (q * 0x1081)
}
return (crc >> 8) ^ (crc << 8)
View gist:d865de5afdbd91c477cf
1 2 3 4 5 6
$('.checkrate').click(function (e) {
e.preventDefault();
var fromObj = fromPicker.get('select');
var toObj = toPicker.get('select');
hhotelDispopriceFHP('ASIATHBKHTLATSiam', '', '', fromObj.year, fromObj.month + 1, fromObj.date, (toObj.obj - fromObj.obj) / (1000 * 60 * 60 * 24), $('#adults').val(), $('#children').val(), $('#accesscode').val(), 'THB')
});
View gist:17e8dd8ee421e74b1197
1 2 3 4 5 6 7 8 9
from_date = Date.new(2015, 02, 1)
to_date = Date.civil(2015, 02, -1)
 
attendance_lines_by_date = File.open(ATTENDANCE_LINES_FILE)
.readlines
.map { |line_text| AttendanceLine.new line_text, ROSTER }
.select { |line| line.date >= from_date and line.date <= to_date }
.reject { |line| line.date.weekend? }
.group_by { |line| line.date }
View why_i_<3.rb
1 2 3 4 5 6 7 8 9 10
require 'csv'
 
module Roster
# Example of each row is: [1,Pac,Sivabudh Umpudh,nil,nil,nil,nil,nil,nil]
def self.parse_from_csv filename
CSV.read(filename)
.drop(1) # remove the first row of CSV which is a header
.map(&:compact) # remove all `nil`
.map { |line_array| [line_array[0], "#{line_array[1]} - #{line_array[2]}"] } # convert ["1", "Pac", "Sivabudh Umpudh"] to ["1", "Pac - Sivabudh Umpudh"]
.to_h # convert array to hash: voila, I now got a hash with key as the ID, and value as my name!
View imperative_vs_functional.rb
1 2 3 4 5 6 7 8 9 10
puts "Hello. Welcome to the Functional World!"
 
#
# This is how to do it imperative style (aka: Stupid Java programmer)
#
array = [1,2,3,4]
new_array = []
array.each do |n|
if n % 2 == 0
new_array.push n
View functional_vs_imperative
1 2 3 4 5 6 7 8 9
puts "Hello. Welcome to the Functional World!"
 
# This is how to do it imperative style (Stupid Java programmer)
array = [1,2,3,4]
new_array = []
array.each do |n|
if n % 2 == 0
new_array.push n
end
View gist:f4d170fd817b1ffc97e2
1 2 3 4 5 6 7 8 9 10
$DICTIONARY_FILE = "Main.old.strings"
$FILE_TO_TRANSLATE = "Main.strings"
$TRANSLATED_FILE = "Main.new.strings"
 
module StringsExtraction
def self.extract_english_phrase line
cleaned_up_line = line.delete "/*\n"
tokens = cleaned_up_line.split(";")
token_with_english_phrase = tokens[1]
english_phrase = token_with_english_phrase.split(" = ")[1]
View 0_reuse_code.js
1 2
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View gist:c1ed325628eb17cb4c78
1 2 3 4 5 6 7 8 9
require 'sinatra'
 
get '/hi' do
"Hello World!"
end
 
get '/' do
erb :form
end
Something went wrong with that request. Please try again.