Skip to content

Instantly share code, notes, and snippets.

View jikkujose's full-sized avatar

Jikku Jose jikkujose

View GitHub Profile
@jikkujose
jikkujose / history_histogram.txt
Created January 6, 2015 11:19
History histogram
git 765 ############################################################
gc 653 ####################################################
ag 519 #########################################
h 508 ########################################
c 465 #####################################
dv 416 #################################
rm 342 ###########################
mv 319 ##########################
curl 271 ######################
fo 268 ######################
class RainDrops
SOUNDS = { 3 => 'Pling', 5 => 'Plang', 7 => 'Plong' }
def make_sound(number)
result = SOUNDS.each_with_object([]) do |(factor, sound), record|
record << sound if number % factor == 0
end
result.empty? ? number : result.join
end
end
class Theatre
COST = { running: 3, fixed: 180 }
attr_accessor :number_of_audience, :ticket_price
def revenue
@number_of_audience * @ticket_price
end
def total_cost
class Base
def initialize(alphabets)
@alphabets = alphabets
end
def base
@alphabets.length
end
def to_decimal(number)
require 'minitest'
# require 'minitest/reporters'
# Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new({color: true})]
class Range
include Comparable
def <=>(other)
self.begin <=> other.begin
end
class SittingDuck
include Robot
def tick events
turn_radar 5 if time == 0
fire 3 unless events['robot_scanned'].empty?
turn_gun 10
@last_hit = time unless events['got_hit'].empty?
if @last_hit && time - @last_hit < 20
@jikkujose
jikkujose / hk_flights.rb
Created March 21, 2015 19:48
Quick and dirty implementation of HK flight data parsing
#!/usr/bin/env ruby
require 'curb'
require 'nokogiri'
require 'date'
CURRENT_DATE = Date.today.strftime("%Y-%-m-%d")
link = "http://www.hongkongairport.com/flightinfo/eng/real_arrinfo.do?fromDate<wbr>=#{CURRENT_DATE}"
USER_AGENT = "Mac / Firefox 29: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:29.0) Gecko/20100101 Firefox/29.0"
@jikkujose
jikkujose / vim_right_align.txt
Created May 5, 2015 06:29
Test data for Vim right alignment function
Email Email
Land Land
Mobile Mobile
Address Address
FeedBack FeedBack
Enter (case Enter
@jikkujose
jikkujose / xiaomi_wish_list.markdown
Last active August 29, 2015 14:20
Xiaomi products wish list
  • Thermometer
  • Barometer
  • Plug PC: One that has a battery, networking and can be connected to a wall socket. Refer: [Plug computer][1] OR [Intel Compute Stick][2] (but of course with Linux)
  • Water purifier
  • Induction cooker
  • AC
  • Pen drive
  • Hard disk
  • Desktop speakers
  • Car entertainment sets (MP3 player + speakers)
@jikkujose
jikkujose / count_by_genre.rb
Last active August 29, 2015 14:23
Ruby pipeline
# Original
movies.group_by do |movie|
movie.genre
end.map do |month, list|
[month, list.size]
end.sort_by(&:last).reverse
# Alternative