Skip to content

Instantly share code, notes, and snippets.


Christopher cciollaro

View GitHub Profile
cciollaro / random_method.rb
Last active Dec 17, 2015
Method definition for a wildcard method. You never know what you're gonna get. Example usage: 27.random_method
View random_method.rb
class Object
def random_method
method = self.methods.sample.to_s
print "Calling #{method}: "
return_val = self.instance_eval(method)
puts return_val
rescue Exception => e
puts "it failed (#{e.message})"
cciollaro / fatchat.user.js
Last active Dec 17, 2015
User script to make GMail chats wider. Then Google came out with Hangouts which makes this puppy obsolete.
View fatchat.user.js
// ==UserScript==
// @name GMail FatChat
// @description Widens gmail chats considerably
// @namespace
// @match*
// @version 1.0
// ==/UserScript==
//not pretty code, just wanted to throw something together that worked. google makes it tough by not giving many of their elements unique identifiers.
cciollaro / order_compliant.c
Created May 29, 2013
personal script that checks if a string meets a specified order. example usage: g++ order_compliant.c -o order_compliant cat /usr/share/dict/words | ./order_compliant > accepted_words.txt
View order_compliant.c
#include <iostream>
#include <string>
#include <cstring>
int complies(const char * word){
char order[30];
int wordLength, wordPointer, orderLength, orderPointer;
strcpy(order, "qazwsxedcrfvtgbyhnujmikolp");
cciollaro / tree_builder.rb
Last active Dec 18, 2015
Tree Builder DSL
View tree_builder.rb
class Tree
attr_accessor :elements
def initialize(&block)
@elements = ''
def method_missing(method_name, *args, &block)
@elements << "<#{method_name}>"
View pre-commit
# Git pre-commit hook to check all staged Ruby (*.rb/haml/coffee) files
# for Pry binding references
# Installation
# ln -s /path/to/ /path/to/project/.git/hooks/pre-commit
# Based on
cciollaro / puts_locator.rb
Created Aug 23, 2013
Script to find rogue 'puts'es in a large application.
View puts_locator.rb
FIND_PUTS = false
def puts(*args)
print("#{caller.first}: ")
cciollaro / explode
Last active Dec 23, 2015
move everything in a directory to the same level as the directory. then rm the directory.
View explode
if [ $# -eq 0 ]
echo "usage: explode <dir>"
exit 1
mv $1/* $1/..
rm -r $1
cciollaro /
Last active Dec 24, 2015
Survivor Solution in Java using Recursion
//There are 100 people sat at a circular table.
//You go around the table asking every second person to leave (starting by asking the guy at seat 1 to leave) until there is one person left.
//Which seat is left?
//usage: java Survivor 100
class Survivor {
public static void main(String[] args){
int n = Integer.parseInt(args[0]);
int result = eliminate(1, 1, n, false);
cciollaro /
Created Oct 5, 2013
stable counting sort in java
public class CountingSort{
public static void main(String[] args){
int[] a = {5,6,7,1,2,4,5,6,1,0,3,4,2};
printArray(countingSort(a, 7));
public static int[] countingSort(int[] a, int k){
int[] b = new int[a.length];
int[] c = new int[k + 1];
for(int i = 0; i < a.length; i++)
cciollaro /
Created Oct 17, 2013
A right-to-left binary modular exponentiation algorithm in java i.e. calculating a^b mod n
public class ModExp {
public static void main(String[] args) {
public static int modExp(int a, int b, int n){
int d = 1;
String k = Integer.toBinaryString(b);
for(int i = 1; i <= k.length(); i++){