Skip to content

Instantly share code, notes, and snippets.

View gimenete's full-sized avatar

Alberto Gimeno gimenete

View GitHub Profile
@gimenete
gimenete / gist:9377962
Created March 5, 2014 22:26
Run less.js in a sandbox
var fs = require('fs')
var path = require('path')
var vm = require('vm')
var util = require('util')
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
}
var basedir = path.join(__dirname, 'less_files')+path.sep
Backbeam.addRealTimeConnectionListener(new RealTimeConnectionListener() {
@Override
public void realTimeConnecting() {
System.out.println("connecting...");
}
@Override
public void realTimeConnected() {
System.out.println("connected");
@gimenete
gimenete / chain.js
Last active August 29, 2015 14:07
Promises-like control flow without promises
module.exports = function(f) {
var pro = {}
var chain = []
var end = null
function next() {
var f = chain.shift()
if (!f) {
end.apply(null, arguments)
} else {
<?php
function seo($url) {
$url = strToLower($url);
$url = str_replace(
array("á", "é", "í", "ó", "ú", "ñ", "ü"),
array("a", "e", "i", "o", "u", "n", "u"),
$url);
$tokens = preg_split("/[^a-zA-Z0-9]+/", $url);
$url = implode("-", $tokens);
@gimenete
gimenete / Json.java
Created August 5, 2011 13:37
Optimized Json simple parser / generator. Works in Android
/*
* Copyright 2009-2011 Alberto Gimeno <gimenete at gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@gimenete
gimenete / index.html
Created November 17, 2011 16:34
Template engine proposal
<!--
Goal: use your mockups as templates
Do not repeat yourself. Don’t make mockups AND templates. Do both at the same time. Your template is your mockup, so it can be seen in your browser and you can use the same text editor you are using for your mockups.
But how?
With a template engine that uses especial HTML attributes that are removed during template execution.
These non-standard HTML attributes are ignored by web browsers.
@gimenete
gimenete / gist:3237060
Created August 2, 2012 13:20
Minor aesthetic proposal for sentinel configuration

This is the current pattern for configuration options

port 26379
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 900000
sentinel can-failover mymaster yes
sentinel parallel-syncs mymaster 1

I think this is much more legible since all options begin in the same character column

@gimenete
gimenete / Default (OSX).sublime-keymap
Created August 24, 2012 10:07
SublimeText2 plugin for escaping code. Useful for languages that don't support heredoc
[
{
"keys": ["command+ctrl+e"], "command": "escape_code"
}
]
@gimenete
gimenete / Default (OSX).sublime-keymap
Created August 24, 2012 13:57
SublimeText2 plugin that translates the selected code to HTML
[
{
"keys": ["command+ctrl+h"], "command": "highlight_code"
}
]
@gimenete
gimenete / promises.js
Last active December 15, 2015 22:39
Comparing Q.js and async.js
var Q = require('q')
var async = require('async')
function dumbQ(value) {
var deferred = Q.defer()
setTimeout(function() {
deferred.resolve(value)
}, 200)
return deferred.promise
}