Skip to content

Instantly share code, notes, and snippets.

View johnHackworth's full-sized avatar

Javi A. johnHackworth

  • Madrid, Spain
View GitHub Profile
function clone(param) {
function cloneArray(arr) {
var clonedArr = [];
for(var el in arr) {
clonedArr.push(clone(arr[el]));
}
return clonedArr;
}
@johnHackworth
johnHackworth / badInheritance.js
Created August 2, 2012 23:13
Example of problems with constructor extension instead of prototype extension
var Company = function() {
for(var m in this) {
if(typeof(this[m]) !== "function") {
this[m] = $.extend(true, {}, this[m])
}
}
}
Company.prototype.office = {
address: {
'street': 'A'
@johnHackworth
johnHackworth / exploreCarto
Created October 4, 2012 11:27
explore all the subviews of cartodb
var explore = function(root) {
for(var v in root._subviews) {
var view = root._subviews[v];
var data = {
name: view.className,
element: view.el,
view: view
}
console.log(data)
explore(view)
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
section {
background-color: #FFF;
min-width: 1056px;
}
ol {
@johnHackworth
johnHackworth / theremin.js
Created October 27, 2012 13:06
quick theremin
// only webkit, please
var DoFreq = 261;
var SiFreq = 494;
var rangeFreq = DoFreq - SiFreq;
var context = new webkitAudioContext();
var sineWave = context.createOscillator();
sineWave.connect(context.destination);
sineWave.noteOn(1);
window.addEventListener('mousemove', function(ev) {
var totalSize = window.document.width;
@johnHackworth
johnHackworth / instruments.js
Created October 27, 2012 13:23
instruments
// only webkit, please
var Instrument = function() {
var self = this;
this.context = new webkitAudioContext();
this.sineWave = this.context.createOscillator();
this.sineWave.connect(this.context.destination);
this.play = function() {
self.sineWave.noteOn(1);
};
this.stop = function() {
@johnHackworth
johnHackworth / silbido.js
Created October 27, 2012 17:32
read you page with an oscillator
// only webkit, please
// bookmarklet:
// javascript:(function(){var context = new webkitAudioContext(); var sineWave = context.createOscillator(); sineWave.connect(context.destination); sineWave.noteOn(1); var text = document.body.innerHTML.split(''); var read = function(text, sineWave) { var char = text.pop(); var value = char.charCodeAt(0); sineWave.frequency.value = value * 10; setTimeout(function() { read(text, sineWave); }.bind(this), 50); }; read(text, sineWave);})()
var context = new webkitAudioContext();
var sineWave = context.createOscillator();
sineWave.connect(context.destination);
sineWave.noteOn(1);
@johnHackworth
johnHackworth / invertColorRamps.js
Created November 14, 2012 19:06
get inverted cdb.admin.color_ramps
function reverseColors(colors) {
var reversed = {}
for(var color in colors) {
reversed['inverted_' + color] = {};
for(var i in colors[color]) {
reversed['inverted_' + color][i] = colors[color][i].reverse();
}
}
return reversed;
}
@johnHackworth
johnHackworth / robot.js
Created December 5, 2012 11:00
searcher v1
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.seed = 1;
Robot.prototype.detected = false;
Robot.prototype.heading = false;
Robot.prototype.onIdle = function(ev) {
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'vinyl', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}