This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from cerberus import Validator | |
class Validator(Validator): | |
def _validate_is_uuid(self, is_uuid, field, value): | |
re_uuid = re.compile(r'[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}', re.I) | |
if is_uuid and not re_uuid.match(value): | |
self._error("Value for field '%s' must be valid UUID" % field) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// libuuid sample program | |
// | |
// library install for debian | |
// $ sudo apt-get install uuid-dev | |
// | |
// compile | |
// $ gcc uuid_test.c -luuid -o uuid_test | |
// | |
#include <stdio.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js | |
*/ | |
var http = require('http'), | |
fs = require('fs'), | |
util = require('util'); | |
http.createServer(function (req, res) { | |
var path = 'video.mp4'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Q = require('q'); | |
var f = function(a) { | |
var defer = Q.defer(); | |
setTimeout(function() { | |
console.log(a); | |
defer.resolve(a); | |
}, a); | |
return defer.promise; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Q = require('q'); | |
var f = function(a) { | |
var defer = Q.defer(); | |
if (a % 2 === 0) | |
defer.resolve(a); | |
else | |
defer.reject(new Error("Rejected, module is odd" + a)); | |
return defer.promise; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript> | |
function fisherYates ( myArray ) { | |
var i = myArray.length, j, temp; | |
if ( i === 0 ) return false; | |
while ( --i ) { | |
j = Math.floor( Math.random() * ( i + 1 ) ); | |
temp = myArray[i]; | |
myArray[i] = myArray[j]; | |
myArray[j] = temp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"github.com/codegangsta/negroni" | |
"github.com/gorilla/mux" | |
"log" | |
"net/http" | |
"strconv" | |
) |
OlderNewer