Skip to content

Instantly share code, notes, and snippets.

View ardbytes's full-sized avatar
💭
Ruby, CSS, Math, ...

Arvind ardbytes

💭
Ruby, CSS, Math, ...
View GitHub Profile
@ardbytes
ardbytes / base64.rb
Last active February 10, 2018 08:37
Encode text to base64
# References:
#
# https://en.wikipedia.org/wiki/Base64
require 'base64'
TABLE = ('A'..'Z').to_a + ('a'..'z').to_a + ("0".."9").to_a + ['+','/']
class String
def bit_string
@ardbytes
ardbytes / tic-tac-toe.rb
Created December 31, 2016 10:58
TicTacToe
PLAYER_SYMBOL = "X"
COMPUTER_SYMBOL = "O"
WINNING_COMBINATION =
{
0 => [[0, 1, 2], [0, 3, 6], [0, 4, 8]],
1 => [[0, 1, 2], [1, 4, 7]],
2 => [[0, 1, 2], [2, 5, 8], [2, 4, 6]],
3 => [[0, 3, 6], [3, 4, 5]],
4 => [[0, 4, 8], [3, 4, 5], [2, 4, 6], [1, 4, 7]],

Context

This tweet explains it all.

I have a huge pile of papers on my computer waiting to be read. Often I read parts of it immediately after I see the paper, but I forget about it until someone points on another article, how awesome that paper is. I then remember to read it more carefully.

One way to fix it is to work with like minded people and have serious (non-hand wavy) discussion around the paper.

The list below will grow. My hard disk has more papers than I can count. I have carefully chosen a list of very readable papers in the list below. Special thanks for the authors for publishing their great ideas.

@ardbytes
ardbytes / bottom_up_merge_sort.rb
Created March 23, 2014 11:07
Bottom-up merge sort in Ruby
def merge_sort(a, lo, mid, hi)
# a[lo..mid] and a[mid+1..hi] must be sorted
dup = a.clone
# index for the left sub-array: lo <= i <= mid
i = lo
# index for the right sub-array: mid+1 <= j <= hi
@ardbytes
ardbytes / clojure_concepts.txt
Created May 21, 2013 19:04
Important Clojure concepts
* Immutability
- Persistent data-structures. Once created, cannot be changed.
- All modifications result in a new data-structure being created.
- New data-structures are efficiently created from old ones through structural sharing.
* Identity
- Identity is logical.
- Changes over time. For example, Kaveri River.
* State
@ardbytes
ardbytes / factorial.clj
Created May 21, 2013 17:59
Factorial in Clojure
(defn factorial [n]
(apply * (range 1 (inc n))))
(println (format "Factorial of 5 is: %s" (factorial 5)))
#!/usr/bin/zsh
# post-checkout hook to adjust heroku.remote based on the branch being checked out.
#
# Do nothing on file checkout
[[ $3 -eq 0 ]] && exit
echo "Fixing heroku.remote"
current_branch=$(git symbolic-ref HEAD)
@ardbytes
ardbytes / yahoo_oauth
Created February 28, 2011 13:31
Get your Yahoo! contacts through Yahoo OAuth on the command line
require "oauth"
@consumer_key = <your-consumer-key>
@consumer_secret = <your-consumer-secret>
@consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret,
{
:site => 'https://api.login.yahoo.com',
:request_token_path => '/oauth/v2/get_request_token',
:access_token_path => '/oauth/v2/get_token',
@ardbytes
ardbytes / Http Codes
Created January 13, 2011 10:21
Http Codes to consider
200 : OK
201 : CREATED
202 : ACCEPTED
204 : No Content
301 : Moved Permanently
302 : Found
303 : See Other
304 : Not Modified
307 : Temporary Redirect
400 : Bad Request
@ardbytes
ardbytes / OOP Guidelines
Created January 5, 2011 14:27
OOP Guidelines
* Always tell never ask.
* Never use if's.
* Never create objects that don't have both state and methods.