Skip to content

Instantly share code, notes, and snippets.

View bheeshmar's full-sized avatar

Bheeshmar Redheendran bheeshmar

View GitHub Profile
@bheeshmar
bheeshmar / easter.py
Created April 21, 2019 02:13
Reveal the location of the missing egg!
# To get the clue, enter the correct seed.
# If you don't know it, we know where you live!
import random
secret = # guess me
random.seed(secret)
words = "longing rusted furnace daybreak seventeen benign nine homecoming cash one freight car bubble flush calculator smash with book blow invincible".split(' ')
code = random.sample(words, 3)
print('Clue: ' + ' '.join(code))
@bheeshmar
bheeshmar / splitwords.bash
Last active August 29, 2015 14:27
Word splitter solution in bash
#!/bin/bash
# call with ./splitwords.bash thisisawesome
find_substrings() {
local remainder=$1
matched=$2
# echo "in find_substrings '${remainder}' (${matched[@]})"
if [[ -z $remainder ]]; then
echo "Found: ${matched[@]}"
exit 0
### MY CUSTOMIZATIONS
# Set hostname, etc
export DESIREDHOSTNAME=viminal
sudo scutil --set HostName $DESIREDHOSTNAME
sudo scutil --set LocalHostName $DESIREDHOSTNAME
sudo scutil --set ComputerName $DESIREDHOSTNAME
# Mac terminal doesn't load .bashrc by default
echo "[ -f ~/.bashrc ] && . ~/.bashrc" >> ~/.bash_profile
@bheeshmar
bheeshmar / fact.exs
Created May 3, 2015 02:46
Many faces of Factorial in Elixir
defmodule Foo do
# Use case matching
def fact1(n) do
case n do
1 -> 1
_ -> n * fact1(n-1)
end
end
@bheeshmar
bheeshmar / dirmd5.go
Last active August 29, 2015 14:19
Print filetree of current directory with md5sums of files
package main
import (
"crypto/md5"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
def counts_of_files_by_extension(dir)
Dir["#{dir}/**/*"].reduce(Hash.new(0)) do |extension_counts, filepath|
extension_counts[File.extname(filepath)] += 1
extension_counts
end
end
directory = ARGV.shift || Dir.pwd
counts = counts_of_files_by_extension(directory)
module Foo
def included(base)
base.extend ClassMethods
# We need to call these AR methods ON the class
base.class_eval do
after_commit :foo
end
end
module ClassMethods
@bheeshmar
bheeshmar / gnome-terminal-colors-for-putty.reg
Created February 27, 2012 18:43 — forked from tjensen/gist:1912325
I finally got fed up enough with PuTTY's default ANSI colors that I customized them to match the gnome-terminal settings on Ubuntu 10.04
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings]
"Colour6"="0,0,0"
"Colour7"="85,87,83"
"Colour8"="204,0,0"
"Colour9"="239,41,41"
"Colour10"="78,154,6"
"Colour11"="138,226,52"
"Colour12"="196,160,0"
@bheeshmar
bheeshmar / textaid.rb
Created February 7, 2012 22:28
Webserver for Textaid Chrome plugin
require 'webrick'
require 'tempfile'
# Start gvim in foreground mode
$EDITOR = "gvim -f "
s = WEBrick::HTTPServer.new(:Port => 9292)
%w(INT TERM).each { |signal| trap(signal) { s.shutdown } }
s.mount_proc("/") do |req,res|
t = Tempfile.open('textaid') { |f| f.write(req.body); f }
@bheeshmar
bheeshmar / conversions.rb
Created April 11, 2011 22:53
Behavior of different conversion operators provided by Kernel
values = [nil, '', [], {}, true, false, 0, 3.51, '0', '42', '0xb', '1.2', '1e2',
'nil', 'true', 'false' ,'foo', [3,4], {5=>6}]
converters = %w(String to_s Integer to_i Float to_f Array to_a)
table_format = "%9s" * converters.size + "\n"
printf( "%9s ", '')
legend = converters
printf(table_format, *legend)
values.each do |v|