Skip to content

Instantly share code, notes, and snippets.

View gimenete's full-sized avatar

Alberto Gimeno gimenete

View GitHub Profile
<?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 / collector.js
Last active April 18, 2024 17:59
Simple utility for parallel execution of asynchronous tasks in JavaScript
function collector() {
var c = {}, errors = {}, results = {}, pending = 1, callback = null
c.bind = function(name) {
pending++
return function(err, result) {
if (err) errors[name] = err
else results[name] = result
fireIfFinished()
}
@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
}
@gimenete
gimenete / index.html
Created April 29, 2013 13:52
With the tl;dr extension enabled, follow the steps described in the commented source code.
<h1>tldr leaks memory?</h1>
<!-- Start recording with Chrome Dev Tools using the "Timeline" section. Click 'start' and see the memory usage -->
<!-- pushState() does not work with local files, so you can save this file as 'index.html',
start a static Python web server with `python -m SimpleHTTPServer` in the same directory and open http://localhost:8000/ -->
<button onclick="start()">Start!</button>
<script>
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'Andorra', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},