Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher cciollaro

View GitHub Profile
@cciollaro
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
begin
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})"
retry
@cciollaro
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 http://chrisciollaro.com
// @match https://mail.google.com/mail/*
// @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
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
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 = ''
instance_eval(&block)
end
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/pre-commit.sh /path/to/project/.git/hooks/pre-commit
#
# Based on
#
# http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/
@cciollaro
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
if FIND_PUTS
def puts(*args)
print("#{caller.first}: ")
super
end
end
@cciollaro
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
#!/bin/sh
if [ $# -eq 0 ]
then
echo "usage: explode <dir>"
exit 1
fi
mv $1/* $1/..
rm -r $1
@cciollaro
cciollaro / Survivor.java
Last active Dec 24, 2015
Survivor Solution in Java using Recursion
View Survivor.java
//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);
System.out.println(result);
}
@cciollaro
cciollaro / CountingSort.java
Created Oct 5, 2013
stable counting sort in java
View CountingSort.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
cciollaro / ModExp.java
Created Oct 17, 2013
A right-to-left binary modular exponentiation algorithm in java i.e. calculating a^b mod n
View ModExp.java
public class ModExp {
public static void main(String[] args) {
System.out.println(modExp(4,13,497));
}
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++){