Skip to content

Instantly share code, notes, and snippets.

View ballpointcarrot's full-sized avatar
💭
Perpetually confused.

Christopher Kruse ballpointcarrot

💭
Perpetually confused.
View GitHub Profile
def word_to_hash(word)
primes = {
'a' => 2, 'b' => 3, 'c' => 5, 'd' => 7, 'e' => 1, 'f' => 13, 'g' => 17,
'h' => 19, 'i' => 23, 'j' => 29, 'k' => 31, 'l' => 37, 'm' => 41,
'n' => 43, 'o' => 47, 'p' => 51, 'q' => 53, 'r' => 59, 's' => 61,
't' => 67, 'u' => 71, 'v' => 73, 'w' => 79, 'x' => 83, 'y' => 97,
'z' => 101
}
sum = 1
word.split('').each{|ch|
package com.cornerofseven.android.lwp.paint;
import android.graphics.Paint;
import android.hardware.SensorManager;
import android.service.wallpaper.WallpaperService;
import android.view.SurfaceHolder;
/**
* PaintService
* Basic setup to create an Android Live Wallpaper.
class PaintEngine extends Engine implements SensorEventListener {
private final Paint[] mCardinalPaints = new Paint[4];
private final Runnable mDrawWP = new Runnable(){
public void run() {
drawFrame();
}
};
private SensorManager mSensMgr =
(SensorManager) getSystemService(SENSOR_SERVICE);
@ballpointcarrot
ballpointcarrot / _form.html.haml
Created March 3, 2011 00:34
Examle Rails locale YAML to customize Form Label names
~ form_for(@race) do |f|
~ if @race.errors.any?
#error_explanation
%h2 #{pluralize(@race.errors.count, "error")} prohibited this race from being saved:
%ul
~@race.errors.full_messages.each do |msg|
%li= msg
.field
=f.label :name
%br
@ballpointcarrot
ballpointcarrot / fizzbuzz.rb
Created April 13, 2011 03:05
A FizzBuzz-styled programming question for a job application.
def fizzbuzz
fifteens = temp = 0
0.upto(1000).collect do |x|
fifteens += x if x % 15 == 0
temp += x if ((x % 3 == 0) ^ (x % 5 == 0))
end
puts "Single fifteens: #{temp + fifteens}"
puts "Double fifteens: #{temp + (fifteens * 2)}"
end
@ballpointcarrot
ballpointcarrot / primes.rb
Created April 18, 2011 04:01
A comparison between the mathn library in Ruby and a self-built solution for prime generation.
require 'mathn'
# Generates a list of primes below a given value
def primelist(n)
k = 1
a = [2,3]
while 6*k < n
a.push(6*k-1)
a.push(6*k+1)
k += 1
@ballpointcarrot
ballpointcarrot / spiral_numbers.rb
Created April 19, 2011 03:45
Calculating the diagonal sum of a number spiral, with '1' in the center.
#adds the diagonals of a number spiral (where 1 is center)
def spiral(n)
sum = 1
max = n**2
corner = 1
step = 2
while corner < max
4.times do |i|
corner += step
sum += corner
@ballpointcarrot
ballpointcarrot / sum_squares.rb
Created April 20, 2011 15:39
A simple solution to finding the difference of the "square of the sums" and the "sum of the squares."
def sums(n)
(1..n).inject(0){|sum,i| sum + i**2}
end
def squares(n)
(1..n).inject(0){|sum, i| sum + i} ** 2
end
puts squares(100) - sums(100)
@ballpointcarrot
ballpointcarrot / main.go
Created September 17, 2011 17:46
opengl tutorial 0
package main
import(
"fmt"
"gl"
"gl/glu"
"os"
"sdl"
)
@ballpointcarrot
ballpointcarrot / letter_count.c
Created October 8, 2011 16:56
Letter Distribution Calculator
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "letter_count.h"
int main (int argc, char const* argv[])
{
int i;
for (i=1;i<argc; i++){
letter_distribution_of(argv[i]);