Skip to content

Instantly share code, notes, and snippets.

View eduardonunesp's full-sized avatar
🐚

Eduardo Pereira eduardonunesp

🐚
View GitHub Profile
'use strict';
import Hapi from 'hapi';
import Promise from 'bluebird';
const server = new Hapi.Server();
server.register([
require('hapi-async-handler')
], function(error) {
@eduardonunesp
eduardonunesp / gist:8362413
Created January 10, 2014 20:55
Format brazilian phone numbers
def formatPhone(phone):
formatted = ''
i = 0
# clean phone. skip not digits
phone = ''.join(x for x in phone if x.isdigit())
# set pattern
if len(phone) == 12:
pattern = '(XXX) XXXXX-XXXX'
@eduardonunesp
eduardonunesp / mysqldump2djangoclass.py
Created January 13, 2014 17:58
The idea is make easy to migrate of a huge mysql table and translate to Django ORM (incomplete)
import re
import sys
CREATE_TABLE_STATEMENT = re.compile('CREATE\s+TABLE\s+(IF\s+NOT\s+EXISTS\s+)?`?(\w+)`?\s+\(', re.I)
END_CREATE_TABLE_STATEMENT = re.compile('\)\s*(ENGINE\s*=\s*(\w+))?\s*;', re.I)
STRUCTURE_FIELD = re.compile('\s+((?!UNIQUE)(?!PRIMARY)(?!KEY)(?!INDEX)`?\w+`?.*),', re.I)
CONSTRAING_FIELD = re.compile('\s+(UNIQUE.*|KEY.*|INDEX.*),?', re.I)
EXTRACT_VARCHAR_TYPE = re.compile('`?\w+`?\s+(VARCHAR\((\d+)\))\s+', re.I)
EXTRACT_INT_TYPE = re.compile('`?\w+`?\s+(INT\((\d+)\))\s+', re.I)
@eduardonunesp
eduardonunesp / esnextbin.md
Last active April 6, 2016 12:38
esnextbin sketch
Function.prototype.partial = function() {
// CODE HERE
var fn = this, args = Array.prototype.slice.call(arguments);
return function() {
var replace = function(arr) {
var pos = 0;
return {
next : function() {
return arr[pos++];
@eduardonunesp
eduardonunesp / esnextbin.md
Created April 27, 2016 17:40
esnextbin sketch
@eduardonunesp
eduardonunesp / http.js
Last active May 17, 2016 01:09
Node HTTP + Ramda
'use strict'
const R = require('ramda');
const http = require('http');
const log = function() {
const args = [].slice.call(arguments);
if (R.all(v => v, args)) {
console.log.apply(console.log, args);
}
const log = function(args) {
args = Array.isArray(args) ? args : Array.prototype.slice.call(arguments)
console.log.apply(console, args);
};
const tOut = function(time) {
return new Promise(function(resolve) {
setTimeout(() => {
resolve(time);
}, time);
var arr = [
[-1, 1, -1, 0, 0, 0],
[ 0, -1, 0, 0, 0, 0],
[-1, -1, -1, 0, 0, 0],
[ 0, -9, 2, -4, -4, 0],
[-7, 0, 0, -2, 0, 0],
[ 0, 0, -1, -2, -4, 0]
];
const sum = (a, b) => a + b;
@eduardonunesp
eduardonunesp / tomilitaryhour.js
Created April 15, 2016 15:04
Time Conversion
/*
Given a time in AM/PM format, convert it to military (2424-hour) time.
Note: Midnight is 12:00:00AM12:00:00AM on a 1212-hour clock, and 00:00:0000:00:00 on a 2424-hour clock. Noon is 12:00:00PM12:00:00PM on a 1212-hour clock, and 12:00:0012:00:00 on a 2424-hour clock.
Input Format
A single string containing a time in 1212-hour clock format (i.e.: hh:mm:ssAMhh:mm:ssAM or hh:mm:ssPMhh:mm:ssPM), where 01≤hh≤1201≤hh≤12.
Output Format