Skip to content

Instantly share code, notes, and snippets.

View alexanderjeurissen's full-sized avatar

Alexander Jeurissen alexanderjeurissen

View GitHub Profile
var hashCode = function(s) {
return s.split("").reduce(function(a, b) {
a = ((a << 5) - a) + b.charCodeAt(0);
return a & a
}, 0);
}
public string pastelColorForString (string s) {
UInt32 hashCode = BitConverter.ToUInt32 (
new SHA1CryptoServiceProvider ().ComputeHash (
Encoding.UTF8.GetBytes (s)
),0
);
return "#" +
((((hashCode >> 24) & 0xFF)+255)/2).ToString ("X") +
((((hashCode >> 16) & 0xFF)+255)/2).ToString ("X") +
@alexanderjeurissen
alexanderjeurissen / reverse string prototype
Created January 5, 2014 17:04
In javascript the fastest way to reverse a string is to first create a Char array , then reverse the array then join it. In a recent project i wanted to revert strings and didn't want to duplicate "string value".split("").reverse().join(""); therefore i created a String.prototype so i can just call "string value".reverse();
String.prototype.reverse = function () {
return this.split("").reverse().join("");
}
@alexanderjeurissen
alexanderjeurissen / stringToPastel.js
Last active January 2, 2016 07:49
String to pastelcolor script. If added to your project you can simply use: "string to be converted".getPastel(); to convert the string to a pastel color.
String.prototype.getPastel = function (rgb) {
var radix = (!rgb) ? 16 : 10;
var hashCode = this.split("").reduce(function (a, b) {
a = ((a << 5) - a) + b.charCodeAt(0);
b = ((b << 5) - b) + a;
return a << b;
}, 0);
var rad = function (bitshift) {
@alexanderjeurissen
alexanderjeurissen / Git flow test.md
Last active April 11, 2016 19:37
Git flow test

#Git-flow tutorial

by Alexander Jeurissen

I created a test repository on Github to check if git-flow can aid in keeping a clean branch model. In the steps below you can see how I create a new feature and release containing our new feature.

  1. Create remote repository on Github
  2. Clone de remote repo with git clone
  3. Init git flow with defaults: git flow init -d

result:

; .editorconfig
root = true
[**.js]
brace_style = collapse, end-expand, expand-strict
break_chained_methods = false
e4x = false
eval_code = false
indent_style = space
@alexanderjeurissen
alexanderjeurissen / Scale.js
Created February 27, 2014 16:56
This function scales the given value from one domain to another. scale( [a,b] , [min,max] , a ) = min AND scale( [a,b] , [min,max] , b ) = max
var scale = function (sourceDomain, targetDomain, x) {
var sourceMin = sourceDomain[0];
var sourceMax = sourceDomain[1];
var targetMin = targetDomain[0];
var targetMax = targetDomain[1];
return {
value: (((targetMax - targetMin) * (x - sourceMin)) / (sourceMax - sourceMin)) + targetMin,
scalingFactor: (targetMax - targetMin) / (sourceMax - sourceMin)
@alexanderjeurissen
alexanderjeurissen / charCodes.coffee
Last active August 29, 2015 13:56
A string prototype that returns an array of char codes for the given string.
String::charCodes = ->
@split("").reduce (previousValue, currentValue, index, array) ->
array[index] = currentValue.charCodeAt 0
array
, 0
@alexanderjeurissen
alexanderjeurissen / toBinary.coffee
Created March 2, 2014 23:54
String prototype that converts the given message to a binary String.
//coffescript version
String::toBinary = ->
@split("").reduce (result, char) ->
bin = char.charCodeAt(0).toString(2)
result += "00000000".slice(0, 8 - bin.length) + bin
, ""
" E 888 888 d88b
" d8b 888 e88~~8e Y88b / /~~~8e 888-~88e e88~\888 e88~~8e 888-~\ Y88P d88~\
" /Y88b 888 d888 88b Y88b/ 88b 888 888 d888 888 d888 88b 888 __/ C888
" / Y88b 888 8888__888 Y88b e88~-888 888 888 8888 888 8888__888 888 Y88b
" /____Y88b 888 Y888 , /Y88b C888 888 888 888 Y888 888 Y888 , 888 888D
" / Y88b 888 '88___/ / Y88b `88_-888 888 888 '88_/888 "88___/ 888 \_88P
" Y88b / ,e,
" Y88b / " 888-~88e-~88e 888-~\ e88~~\