Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Eckel bhelx

View GitHub Profile
View Particle_extention.java
public class BoxParticle extends Particle {
int color;
int size;
public BoxParticle(PVector location, int color, int size) {
super(location);
this.color = color;
this.size = size;
}
View base_62_converter.py
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
View remembrances.rb
# Learning ruby, trying to remember these fun facts
#--ARRAYS
#--#--Useful functions
[1, 2, 3, 4].any? {|n| n > 2} #=> true
[1, 2, 3, 4].all? {|n| n > 2} #=> false
#--#--collect and map (collect! and map!)
a = [ "a", "b", "c", "d" ]
@bhelx
bhelx / binary_sort.rb
Last active Oct 10, 2016
BINARY SORT FOR EXERCISE.
View binary_sort.rb
class BinaryTree
attr_accessor :value, :left, :right
def insert(value)
if @value
if value < @value
@left ||= BinaryTree.new
@left.insert(value)
else
@bhelx
bhelx / deep_write.rb
Created Oct 8, 2011
write a file in a directory that may not exist
View deep_write.rb
require 'fileutils'
def deep_write(f, data)
FileUtils.mkdir_p(File.dirname(f)) unless File.directory?(File.dirname(f))
File.open(f, 'w').write(data)
end
@bhelx
bhelx / index.html
Created Dec 15, 2011
"tail -f" a file node 0.6.5 pipe to socket.io,
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Websockets tail Server</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<style type="text/css" rel="stylesheet">
body{background-color:#222;}
#info{ font-size: 32px; color:#000;text-shadow:#444 1px 1px 2px; text-align:right;margin:20px 10px;text-transform:lowercase;}
@bhelx
bhelx / libtre_test.c
Created Dec 19, 2011
test of libtre fuzzy regex matcher
View libtre_test.c
Compiled Regex
Created Default params
cost_ins -> 1
cost_del -> 1
cost_subst -> 1
max_cost -> 2147483647
max_ins -> 2147483647
max_del -> 2147483647
max_subst -> 2147483647
max_err -> 2147483647
@bhelx
bhelx / reduce_flags.rb
Created Jan 21, 2012
reduce bitwise OR flags
View reduce_flags.rb
REG_EXTENDED = 1
REG_ICASE = (REG_EXTENDED << 1)
REG_NOSUB = (REG_ICASE << 1)
REG_NEWLINE = (REG_NOSUB << 1)
flags = [REG_EXTENDED, REG_NOSUB]
p flags.reduce :|
# => 5
View pry_trick.rb
require 'pry'
class Object
LABELS = [:label1, :label2]
def breakpt(label, target=self)
LABELS.include?(label) ? Pry.start(target) : nil
end
@bhelx
bhelx / rb.js
Created Mar 23, 2012
Ruby-esque object construction in javascript
View rb.js
// kind of like ruby openstruct
var OpenObject = function () {
this.construct = function (defaults, params) {
for (var attr in defaults) this[attr] = defaults[attr];
for (var attr in params) this[attr] = params[attr];
};
}
var Circle = function (opts) {
You can’t perform that action at this time.