Skip to content

Instantly share code, notes, and snippets.

View johnHackworth's full-sized avatar

Javi A. johnHackworth

  • Madrid, Spain
View GitHub Profile
@johnHackworth
johnHackworth / gist:e7c8c47c4ceb2f3ab397
Created December 25, 2014 13:01
gif conversion script
mkdir /tmp/tmpVideo/
ffmpeg -t $3 -ss $2 -qscale:v 1 -i $1 /tmp/tmpVideo/out%04d.png
convert -delay 1.8 -loop 0 /tmp/tmpVideo/out*.png /tmp/tmpVideo/tmp.gif
convert -layers Optimize /tmp/tmpVideo/tmp.gif ./out.gif
rm -rf /tmp/tmpVideo
@johnHackworth
johnHackworth / gist:74ed0afbf62e23e99301
Created December 9, 2014 00:59
create sql on the fly
var selectTemplate = "SELECT TOP 5 PERCENT SumOfTRAFFIC_IN_MB as percentile, provincia, mes FROM a_Trafico_Agregado_Provincias_15M WHERE Provincia = '%provincia%' AND Mes = %mes%";
var provincias = ['ALMERIA','BADAJOZ','BALEARES','BARCELONA','BURGOS','CACERES','CADIZ','CANTABRIA','CASTELLON','CIUDAD REAL','CORDOBA','GIRONA','GRANADA','HUELVA','JAEN','LA CORUÑA','LA RIOJA','LEON','LLEIDA','MADRID','MÁLAGA','MURCIA','PONTEVEDRA','SEVILLA','TARRAGONA','TOLEDO','VALENCIA','VALLADOLID','ZARAGOZA'];
var getSelect = function(mes) {
var selects = [];
for(var i in provincias) {
var prov = provincias[i];
var select = selectTemplate.replace('%mes%', mes).replace('%provincia%', prov);
selects.push(select);
@johnHackworth
johnHackworth / gist:88491fed6a7b24f7edc6
Created August 23, 2014 12:52
any way to make this with only one select?
(SELECT *
FROM test1
WHERE test1.interface = '1' ORDER BY traffic DESC LIMIT 2)
UNION
(SELECT *
FROM test1
WHERE test1.interface = '2' ORDER BY traffic DESC LIMIT 2)
UNION
(SELECT *
FROM test1
@johnHackworth
johnHackworth / gist:b6c7da442f3d48a59225
Last active August 29, 2015 14:04
[].removeElement()
Object.defineProperty(Array.prototype, "removeElement", {
value: function(element) {
var found = [];
var i = this.length;
while (i) {
if (this[i - 1] === element) {
found.push(i - 1);
}
i--;
}
@johnHackworth
johnHackworth / gist:6171922
Last active December 20, 2015 17:58
Coffeescript memory leak example
class Alerter
constructor: (name) ->
this.span = document.getElementsByTagName('span')[0]
this.span.addEventListener('click', this.handler)
handler: () -> alert('hello')
window.alerter = new Alerter('hey')
delete window.alerter // ZAS!! Memory leak
var A = function() {}
A.prototype = {
// methods
}
var AMock = function() {}
AMock.prototype = {
// mocked methods
}
@johnHackworth
johnHackworth / maps
Last active December 16, 2015 03:29
// we need to generate 4 html structures for 4 diferent maps, and we use a loop to avoid repeating the same nodes with only different ids.
// also, we need to add each map title from a i18n variable (cpyTitleWhatever)
// any way to do this in a cleaner way?
<%
var maps = ['hits', 'calls', 'registrations', 'map']
_.each(maps, function(e,i) {
%>
<div class="group mapGroup <%= e %>">
<h4><% print(eval('cpyTitle'+e.charAt(0).toUpperCase() + e.slice(1))) %></h4>
@johnHackworth
johnHackworth / gist:5081067
Created March 4, 2013 09:29
foreignObject example
var svg = d3.select("body").append("svg")
.attr("width", 1000)
.attr("height", 1000);
var gatete = svg.append("g").append("foreignObject")
.attr("width", 100)
.attr("height", 100)
.attr('class', 'gatete')
.attr('x', 5)
.attr('y',1)
.append("xhtml:body")
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.
}
}
@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) {