Skip to content

Instantly share code, notes, and snippets.

View gimenete's full-sized avatar

Alberto Gimeno gimenete

View GitHub Profile
@gimenete
gimenete / compare-modules.js
Created October 17, 2014 21:14
Compare your installed node_modules with clean npm install
// mv node_modules node_modules_old && npm install
var fs = require('fs')
var path = require('path')
var node_modules = path.join(__dirname, 'node_modules')
var node_modules_old = path.join(__dirname, 'node_modules_old')
fs.readdir(node_modules, function(err, files) {
files.forEach(function(dir) {
if (dir.charAt(0) === '.') return
@gimenete
gimenete / validate.js
Last active February 28, 2017 14:43
Validate input parameters in node.js requests
var _ = require('underscore')
var util = require('util')
function validate(request) {
var errors = []
var values = {}
var obj = {}
function validator(param) {
@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 {
@gimenete
gimenete / gist:53704124583b5df3b407
Last active July 31, 2020 16:20
Animated rootViewController transition
// put this in your AppDelegate
- (void)changeRootViewController:(UIViewController*)viewController {
if (!self.window.rootViewController) {
self.window.rootViewController = viewController;
return;
}
UIView *snapShot = [self.window snapshotViewAfterScreenUpdates:YES];
[viewController.view addSubview:snapShot];
self.window.rootViewController = viewController;
Backbeam.addRealTimeConnectionListener(new RealTimeConnectionListener() {
@Override
public void realTimeConnecting() {
System.out.println("connecting...");
}
@Override
public void realTimeConnected() {
System.out.println("connected");
@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
@gimenete
gimenete / UIView+ActivityIndicator.h
Created July 11, 2013 09:01
Show an activity indicator in any UIView. Example: [imageView showActivityIndicator]; Then hide it [imageView hideActivityIndicator];
#import <Foundation/Foundation.h>
@interface UIView (ActivityIndicator)
- (void)showActivityIndicator;
- (void)showActivityIndicatorWithStyle:(UIActivityIndicatorViewStyle)style;
- (void)hideActivityIndicator;
@end
[
{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'},
@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>
@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
}