Skip to content

Instantly share code, notes, and snippets.

View eymiha's full-sized avatar

David Anderson eymiha

  • Eymiha
  • Cincinnati, OH USA
View GitHub Profile
@eymiha
eymiha / equibright.rb
Created October 31, 2016 17:40
Given a color with a target perceived brightness and another color with a target hue and saturation, it builds the target color
require "WebColor"
def equibright hex_s, hex_d
color_s = WebColor.new hex_s
color_d = WebColor.new hex_d
h = color_d.hue
s = color_d.saturation
p = color_s.perceived_brightness
puts WebColor.fromHSP(h,s,p).hex
end
@eymiha
eymiha / perceived_brightness.rb
Last active June 29, 2022 21:54
Ruby version of Darel Rex Finley's HSP (hue, saturation, perceived brightness) color model. Go to http://alienryderflex.com/hsp.html for his original work.
class WebColor
attr_accessor :r, :g, :b
@@pr, @@pg, @@pb = 0.299, 0.587, 0.114
@@err = 0.0000001
def initialize r = 0.0, g = 0.0, b = 0.0
if r.is_a? Numeric
@r, @g, @b = r, g, b
else
@eymiha
eymiha / bounding box intersection detection - meteor
Last active August 29, 2015 14:06
validation for bounding box collision detection
Optimised, can detect a non collision in one compare, minimally
collision.html
--------------
<head>
<title>intersect</title>
</head>
<body>
@eymiha
eymiha / soundex.coffee
Last active August 29, 2015 14:02
Soundex algorithm
soundexAlphabet =
'A': 7, 'B': 1, 'C': 2, 'D': 3, 'E': 7, 'F': 1, 'G': 2, 'H': 8, 'I': 7, 'J': 2,
'K': 2, 'L': 4, 'M': 5, 'N': 5, 'O': 7, 'P': 1, 'Q': 2, 'R': 6, 'S': 2, 'T': 3,
'U': 7, 'V': 1, 'W': 8, 'X': 2, 'Y': 7, 'Z': 2, "'": 9, ' ': 9
soundexCode = (name) ->
soundex = []
name = name.trim()
if name.length != 0
index = name.indexOf ' '
@eymiha
eymiha / city_lookups.coffee
Last active August 29, 2015 14:00
Meteor Lookup Tables for US states/cities with more than 8000 people
Meteor.Lookups.insert name: 'location_United States_states', values: 'Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|District of Columbia|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming'
Meteor.Lookups.insert name: 'location_United States_Alabama_cities', values: 'Abernant|Alabaster|Albertville|Alexander City|Andalusia|Anniston|Arab|Athens|Atmore|Attalla|Auburn|Bay Minette|Beauregard-Marvyn|Bessemer|Beulah|Big Sandy-Duncanville|Birmingham|Boaz|Bremen|Center Point|Clanton|Cloverdale|Concord-Hopkins|Craig-Tyler|Cullman|Danville|Daphne|Decatur|Demopolis|Dothan|Enterprise|Eufaula|Fairfield|Fairhope|Florence|Foley|Forestdale|Fort Payne|Fort
@eymiha
eymiha / ColorInterpolator.js
Last active November 27, 2016 23:04
Color Interpolator - when you need to find a color in a colorstop-defined gradient.
// usage: prime with a set of color stops, then ask for colors in the range.
//
// colors = ['#37d78a','#40be8f','#49a594','#538d9a','#5c749f','#655ba4'];
// colorInterpolator = new ColorInterpolator();
// colorInterpolator.prime([
// { value: 0.0, color: colors[0] },
// { value: 0.2, color: colors[1] },
// { value: 0.4, color: colors[2] },
// { value: 0.6, color: colors[3] },
// { value: 0.8, color: colors[4] },
Chicken Tikka Masala
A
6 garlic cloves grated garlic
3 tsp grated ginger
3 tsp turmeric
2 tsp garam masala
2 tsp coriander
2 tsp cumin
@eymiha
eymiha / color.coffee
Created June 6, 2013 03:24
A simple color mechanism in coffeescript conversion, interpolation and four color standards - Crayola crayons, DMC embroidery floss, Pantone colors, and Prismacolor colored pencils.
class @Color
constructor: (red, green, blue) ->
if typeof red == 'string' or red instanceof String
color = red
@r = parseInt(color.substring(1,3),16)
@g = parseInt(color.substring(3,5),16)
@b = parseInt(color.substring(5,7),16)
else if red instanceof Color
color = red
@r = color.r
@eymiha
eymiha / root.coffee
Created June 2, 2013 16:55
Coffeescript global context Because sometimes you want a namespace to hang things from... Creates a Root namespace off the base (node or browser), and establishes an App namespace from it.
Root = exports ? @
App = (Root.App = [])
@eymiha
eymiha / current time
Last active December 17, 2015 18:48
A simple bit of coffeescript (here, for use in meteor) to keep any on-page current timestamps up-to-date.
# using javascript Date
if Meteor.isClient
updateCurrentTimestamps = ->
current = new Date()
year = current.getFullYear()
month = current.getMonth()+1
day = current.getDate()
hour = current.getHours()