Skip to content

Instantly share code, notes, and snippets.

/**
* Read a ISO string
*/
export const fromISOString = (str: string) => {
return Date.parse(str);
};
/** Convert from MilliTimestamp (javascript default) to unix */
export const toUnixTimestamp = (milliTimestamp: number): UnixTimestamp => {
return (milliTimestamp / 1000) as UnixTimestamp;
@vicalejuri
vicalejuri / jinja2_simple_render
Created February 14, 2014 20:14
Jinja2 Simple Render Example
import os
from jinja2 import FileSystemLoader, Environment
template_path = os.getcwd()
# Load jinja
jinja_loader = FileSystemLoader( template_path )
jinja_env = Environment( loader=jinja_loader )
# Get the template and render it using `myvars`
def locawebJSON(data):
_pdata = []
for k,v in data.iteritems():
if type(v) in [str, unicode]:
v = ('"%s"' % (v))
elif isinstance(v, bool):
v = (v and 'true' or 'false')
_pdata.append('%s=%s' % (k,v))
@vicalejuri
vicalejuri / paywall_remove.js
Last active April 11, 2016 23:04
folha.com paywall remover.
$('#paywall').hide();
$('body').css({'overflow': 'scroll'});
window.scroll = undefined;
window.resize = undefined;
#include <stdio.h>
#include <stdlib.h>
char* cycle(int start, int next, int repeatafter, int windowsize){
int j;
char *str = malloc( sizeof(char) * windowsize + 1);
for(j=0;j < windowsize; ++j)
str[j] = 0x30 + ((start + next*j) % (repeatafter+1));
str[j] = '\0';
#!/usr/bin/env python
def crange(tup, i=0, windowsize=3):
l = len(tup)
return "".join([ str(tup[(i+p)%l]) for p in range(0,windowsize)])
r = range(0,6)
for i in range(0,10):
print crange( r, i , 3 )
(define 2ndorder-markov
(lambda (:phrase)
(if (= (length :phrase) 1) (list (first :phrase))
(list (second :phrase)))))
(define 3ndorder-markov
(lambda (:phrase)
(cond
((= (length :phrase) 1) (list (first :phrase)))
((= (length :phrase) 2) (list (second :phrase)))
@vicalejuri
vicalejuri / django-crossdomainxhr-middleware.py
Created June 5, 2010 17:47
Middlware to allow's your django server to respond appropriately to cross domain XHR (postMessage html5 API).
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
We couldn’t find that file to show.
#!/usr/bin/python
import re,sys
def searchInArray( shit, likeStr ):
escape_chars = list( '.^$*+?()[{\\' )
op_chars = list( '%_' )
safe_re = "".join( map( lambda c: c in escape_chars and ('\\' +c) or c , likeStr ) )
match_re = "".join( map( lambda c: c == op_chars[0] and ('.*?') or (c == op_chars[1] and '.' or c) , safe_re ) )