Skip to content

Instantly share code, notes, and snippets.

hunj / rdoc_example.rb
Created May 28, 2015
Ruby RDoc Example
View rdoc_example.rb
## Found in:
# * Style guide based on Rails documention
module Namespace #:nodoc: don't document this
# Generic Namespace exception class
class NamespaceError < StandardError
# Raised when...
hunj / path_stripper.rb
Created Jun 25, 2015
Strip path from domain, off from sitemap xml file.
View path_stripper.rb
def path_strip(input_file, domain, output_file)
raise "domain must be string form" unless domain.is_a? String
raise "invalid input file name" unless input_file.is_a? String
raise "invalid output file name" unless output_file.is_a? String
file =, "r")
data =
data_lines = data.lines
cleared_arr = []
hunj / path_strip.rb
Created Jul 7, 2015
Strip path from domain
View path_strip.rb
# path_strip(input_file, domain, output_file)
# imports an xml file containing paths of the website's pages,
# strips all unnecessary strings except for the path of the pages.
## Parameters:
# +input_file+ name of the input xml file
# +domain+ the domain of the URL to exclude in the result
# +output_file+ name of the output file, ending in .csv (preferred)
def path_strip(input_file, domain, output_file)
raise "domain must be string form" unless domain.is_a? String
raise "invalid input file name" unless input_file.is_a? String
hunj / The Technical Interview Cheat
Last active Aug 29, 2015 — forked from TSiege/The Technical Interview Cheat
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.
View The Technical Interview Cheat

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
hunj / dummy_generate.rb
Created Sep 24, 2015
Generates a dummy file full of 0's and 1's up to desired size
View dummy_generate.rb
DESIRED_SIZE = 1073741824 # 1gb
FILE_NAME = "dummy" # name of the dummy file
dummy_file =, "w")
while dummy_file.size < DESIRED_SIZE
View perfect_number.rb
def perfect_number? number
return number == divisors_of(number)
def divisors_of number
arr = []
(1..number).each do |iter|
if number % iter == 0
arr << iter
hunj / gen.rb
Created Mar 6, 2016
Generate random numbers
View gen.rb
require 'csv'
# Data generation
@data = {}
(0..100).each do |i|
@data[i] = {
:age => Random.rand(18...80),
:gender => Random.rand(0..1),
:prescription_history => []
hunj / euler_003.rb
Last active Jun 15, 2016
Project Euler #003 solution, comparing with square root
View euler_003.rb
require 'benchmark'
the_number = 600_851_475_143
# monkeypatching
class Fixnum
def prime? # O(n)
(2..(self - 1)).each do |divisor|
return false if self % divisor == 0
hunj /
Created Nov 8, 2016
Compute π using Nilakantha's series
from decimal import *
def compute_pi():
pi = Decimal(3.0)
curr_multiplier = Decimal(2)
iteration = Decimal(0)
load = Decimal(1)
getcontext().prec = 6
while 1:
hunj / gist:8549840acc266c1e19761959bd028300
Created Dec 1, 2016
result of running `python 1`
View gist:8549840acc266c1e19761959bd028300
Calculated pi: 3.1411426428303537942242780347543442930366295786973371671458932366545818227278409801225153144143017877234654331791473934241780222527815976997124640580072509063632954119264908113514189273659207400925115639454931866483310413801725215651956494561820227528441055131891486435804475559444930616327040880110013751718964870608826103262907863482935366920865108138517314664333041630203775471933991748968621077634704338042255281910238779847480935116889611201400175021877734716839604950618827353419177397174646830853856732091511438929866233279159894986873359169896237029628703587948493561695211901487685960745093136642080260032504063007875984498062257782222777847230903862982872859107388423552944118014751843980497562195274409301162645330666333291661457682210276284535566945868233529191148893611701462682835354419302412801600200025003125390673834229278659832479059882485310663832979122390298787348418552319039879984998124765595699462432804100512564070508813601700212526565820727590948868608576072009001125140642580322540