Skip to content

Instantly share code, notes, and snippets.

View jasonsperske's full-sized avatar

Jason Sperske jasonsperske

View GitHub Profile
@jasonsperske
jasonsperske / Russian.clj
Created December 5, 2013 00:31
I wanted to try and apply what I have learned writing a JavaScript implementation of the Russian Peasant Algorithm to what I have been learning with Scheme. This works the same way as the JavaScript function :)
(ns Russian)
(defn multiply [& args]
(defn russian_multiply [a b p]
(cond
(> a 0) (russian_multiply (bit-shift-right a 1) (bit-shift-left b 1) (+ p (if (= (mod a 2) 1) b 0)))
:else p))
(defn flip [a] (inc (bit-not a)))
@jasonsperske
jasonsperske / Russian.js
Last active December 30, 2015 04:29
A Google Interview question I was asked over a year ago (and didn't know the answer to). I've since learned how and here is a quick solution in JavaScript (qunit demo at http://jsfiddle.net/at4gU/). I wanted to make something Lisp-y so it takes multiple arguments, deals with negative numbers and passes JSLint (well except for the bitwise operato…
/*jslint bitwise: true */
var multiply = function () {
'use strict';
var fn = function (a, b, product) {
if (a > 0) {
return fn(a >> 1, b << 1, product + (a % 2 === 1 ? b : 0));
}
return product;
},
factors = Array.prototype.slice.call(arguments),
@jasonsperske
jasonsperske / fan.st-logo.py
Created July 25, 2013 17:44
I got tired of resizing and fixing our logo for the myriad of sizes that iPhone, Android and Facebook require, so I wrote a Python script to generate it. There are a couple of hacks (like the gap between the top and bottom half), but it generates our logo with the correct colors and ratios :)
import Image, ImageDraw
box_height = 2
box_width = 6
box_gap_height = 3
box_gap_width = 2
background = (0,0,0)
level_background = (119,120,123)
peeks = (237,26,59)
@jasonsperske
jasonsperske / README.md
Last active December 16, 2015 07:39
JavaScript Obfuscator

Based on @VisioN's profile signature in StackOverflow, turned into a configurator that anyone can use.

import java.util.ArrayList;
import java.util.List;
public class PrimeFactorsOf {
public static void main(String ... args) {
System.out.println(primeFactorsOf(19252389595L));
}
static List<Long> primeFactorsOf(long val) {
long n = val;
using System;
using System.Collections.Generic;
namespace so15415825
{
class Program
{
static void Main(string[] args)
{
var badguys = new List<Badguy>()
from math import pow
from cmath import sqrt
print "Quadradtic Formula Calculator!!!"
print "Ax²+Bx+C=0"
print "This solve for x"
a = input("Please, enter value for A: ")
b = input("Please, enter value for B: ")
c = input("Please, enter value for C: ")
@jasonsperske
jasonsperske / build-bootstrap.bat
Last active December 11, 2015 06:40 — forked from anonymous/my-bootstrap.bat
A batch file that can run on a Windows workstation with Node.js, JSHint, Recess, and UglifyJS to compile Twitter Bootstrap
@ECHO OFF
REM
REM 01.17.2013, Requires Node.js, JSHint, Recess, and UglifyJS (installed in the path)
REM Run this command after node.js is installed
REM npm install -g less jshint recess uglify-js
REM
MKDIR bootstrap\img
MKDIR bootstrap\css
MKDIR bootstrap\js
list_of_lists=[]
category=0
list_of_lists.append([])
f = open("list.txt",'r')
for line in f.readlines():
item = line.strip('\n') # no white spaces in the list
if len(item) > 0:
#add to current category
@jasonsperske
jasonsperske / FizzBuzz-Clean.py
Created July 20, 2012 18:02
A cleaner Fizz/Buzz in Python
# My Third Python program
# Based on this spec: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
import time
import random
def fbPrinter(simulator, translator, i):
time.sleep(simulator(i))
print(translator(i))