Skip to content

Instantly share code, notes, and snippets.

@fudini
fudini / hex2dec, dec2hex
Created March 26, 2011 16:17
convert hex to decimal
function hex2dec(hex) {
hex = hex.toLowerCase(hex).split('');
var dec = 0;
while(h = hex.shift()) {
var code = h.charCodeAt(0);
dec = dec << 4;
dec += code < 58 ? code - 48 : code - 87;
}
return dec;
}
@fudini
fudini / Color conversion
Created April 4, 2011 19:34
various color conversion functions
function hsv2hex(hsv) {
return rgb2hex(hsv2rgb(hsv));
}
function hex2hsv(hex) {
var dec = hex2dec(hex);
var rgb = dec2rgb(dec);
var hsv = rgb2hsv(rgb);
return hsv;
}
/*
var Foo = Class.extend(function() {
this.var1 = "var1 foo";
});
var Bar = Foo.extend(function() {
this.var1 = "var1 bar"
console.log(this.super.var1); // access var1 from the base class
});
- Create EC2 instance - you should have your file.pem public key file saved somewhere.
- Assign Elastic IP.
- Configure security groups for ports 80, 20, pasv ftp range and if you want to enable ping: custom IMCP rule 'echo request'
ssh -i file.pem ubuntu@YOUR_IP
- INSTALL VSFTPD
sudo apt-get install vsftpd
to restart:
@fudini
fudini / gist:6033413
Created July 18, 2013 21:46
List of currencies with symbols and decimal places in JSON format. (ISO-4217)
{
"AED": {
"code": "AED",
"number": "784",
"symbol": "AED",
"decimals": "2"
},
"AFN": {
"code": "AFN",
"number": "971",
/**
* Recursivelly find the first object with the given key
* @param {object} obj Object to search for key
* @param {string} key Key to find
* @return {object} Value if found, undefined if not found
*/
findValueForKey: function(obj, key) {
var value = undefined;
function find(obj, key) {
for(var k in obj) {
@fudini
fudini / gist:60a194665db571a03986
Created September 27, 2014 12:07
Binary search
function split(arr) {
var l = arr.length,
m = Math.round(l / 2);
return {
left: arr.slice(0, m),
right: arr.slice(m, l)
}
}
function find(arr, el) {
// is it a monad?
var x = 1,
fn = x => x + 1,
gn = x => x * 2
var law1 = new Maybe(x).bind(fn).return() == new Maybe(fn(x)).return()
console.log(law1)
var law2 = new Maybe(x).bind(x => x).return() == new Maybe(x).return()
console.log(law2)
@fudini
fudini / gist:ff7882ccd8a51860af31
Last active August 29, 2015 14:10
DataStore with Rx and Ramda
var initialData = []
// These can be converted from other events
var add_ = new Rx.Subject()
var remove_ = new Rx.Subject()
var addF_ = add_.map(R.unary(R.curry(R.union)))
var removeF_ = remove_.map(R.unary(R.flip(R.difference)))
var update = (data, updateF) => updateF(data)
@fudini
fudini / groupByTransformMerge
Last active August 29, 2015 14:20
GroupBy -> transform -> merge
var groupTransform = (stream$, f, keySelector, selector) => {
return Rx.Observable.create(observer => {
var disposable = new Rx.CompositeDisposable()
disposable.add(stream$.groupBy(keySelector, selector)
.subscribe(groupObservable => {
disposable.add(f(groupObservable, groupObservable.key).subscribe(observer))
}))