Skip to content

Instantly share code, notes, and snippets.

View cciollaro's full-sized avatar

Christopher cciollaro

  • Tokyo, JP
  • 17:18 (UTC +09:00)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am cciollaro on github.
  • I am cciollaro (https://keybase.io/cciollaro) on keybase.
  • I have a public key ASDueUTB2-oaIgtSLWsUyhVumh4IYwjYrcCSl0NEur7yygo

To claim this, I am signing this object:

@cciollaro
cciollaro / ModExp.java
Created October 17, 2013 23:36
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) {
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++){

Keybase proof

I hereby claim:

  • I am cciollaro on github.
  • I am cciollaro (https://keybase.io/cciollaro) on keybase.
  • I have a public key whose fingerprint is C448 1E99 EA31 E6C2 3B84 F63D E9FA BDBF 991B DE13

To claim this, I am signing this object:

@cciollaro
cciollaro / socialist_millionaire_sockets.rb
Last active May 10, 2016 21:06
socialist millionaire with tcp sockets
require 'socket'
#http://www.scribd.com/doc/34203336/How-to-Implement-RSA-in-Ruby#download
# Calculate a modular exponentiation eg: b^p mod m
def mod_pow(base, power, mod)
result = 1
while power > 0
result = (result * base) % mod if power & 1 == 1
base = (base * base) % mod
power >>= 1
@cciollaro
cciollaro / test-guide
Created December 7, 2013 20:29
AVM testing structure
let's imagine you wanted to test Coin.js
1.) create test/coinTest.js
2.) write tests like these: http://pivotal.github.io/jasmine/. Jasmine is a really great library, go check out that page! :)
3.) when you've written your test, go to SpecRunner.html and include your test and dependencies like so:
<!-- include source files here... -->
<script type="text/javascript" src="js/Coin.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="test/coinTest.js"></script>
@cciollaro
cciollaro / CountingSort.java
Created October 5, 2013 22:55
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
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/