Skip to content

Instantly share code, notes, and snippets.

View cciollaro's full-sized avatar

Christopher cciollaro

  • Tokyo, JP
  • 08:48 (UTC +09:00)
View GitHub Profile
@cciollaro
cciollaro / Survivor.java
Last active December 24, 2015 15:09
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);
System.out.println(result);
}
@cciollaro
cciollaro / explode
Last active December 23, 2015 23:19
move everything in a directory to the same level as the directory. then rm the directory.
#!/bin/sh
if [ $# -eq 0 ]
then
echo "usage: explode <dir>"
exit 1
fi
mv $1/* $1/..
rm -r $1
@cciollaro
cciollaro / puts_locator.rb
Created August 23, 2013 16:10
Script to find rogue 'puts'es in a large application.
FIND_PUTS = false
if FIND_PUTS
def puts(*args)
print("#{caller.first}: ")
super
end
end
@cciollaro
cciollaro / pre-commit
Last active December 19, 2015 00:28 — forked from alexbevi/pre-commit.sh
# 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 / tree_builder.rb
Last active December 18, 2015 11:39
Tree Builder DSL
class Tree
attr_accessor :elements
def initialize(&block)
@elements = ''
instance_eval(&block)
end
def method_missing(method_name, *args, &block)
@elements << "<#{method_name}>"
@cciollaro
cciollaro / order_compliant.c
Created May 29, 2013 14:10
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
#include <iostream>
#include <string>
#include <cstring>
int complies(const char * word){
char order[30];
int wordLength, wordPointer, orderLength, orderPointer;
strcpy(order, "qazwsxedcrfvtgbyhnujmikolp");
@cciollaro
cciollaro / fatchat.user.js
Last active December 17, 2015 10:48
User script to make GMail chats wider. Then Google came out with Hangouts which makes this puppy obsolete.
// ==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 / random_method.rb
Last active December 17, 2015 07:29
Method definition for a wildcard method. You never know what you're gonna get. Example usage: 27.random_method
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