Skip to content

Instantly share code, notes, and snippets.

View odra's full-sized avatar
💻

odra odra

💻
  • São Paulo, Brazil
View GitHub Profile
@odra
odra / setup-cython.py
Last active September 3, 2015 13:57
cython setup.py file to compile packages
# -*- coding: utf-8 -*-
#source: https://github.com/cython/cython/wiki/PackageHierarchy
import sys, os
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
package_name = 'gd'
package_dir = 'gd'
@odra
odra / deco.py
Created September 14, 2015 14:14
python decorators
# -*- coding: utf-8 -*-
def decorator_without_params(fn):
def wrapper(*args, **kwargs):
fn_result = fn(*args, **kwargs)
return '%s from decorator without params' % fn_result
return wrapper
@odra
odra / ctx.py
Created September 17, 2015 15:30
simple python context manager
# -*- coding: utf-8 -*-
class Greetings(object):
def __init__(self):
self.text = 'hello world'
def say(self):
print 'My engine is: %s' % self.text
@odra
odra / gitignore.py
Last active February 26, 2016 02:19
gitignore file for python project
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
#OSX
.DS_Store
import json
class Model(object):
def __init__(self, *args, **kwargs):
if len(args) > 0 and isinstance(args[0], dict):
for item in args[0]:
setattr(self, item, args[0][item])
for item in kwargs:
setattr(self, item, kwargs[item])
#!/bin/sh
(cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git;
cordova plugin add cordova-plugin-splashscreen;
cordova plugin add cordova-plugin-inappbrowser@~1.2.0;
cordova plugin add cordova-plugin-camera;
cordova plugin add ionic-plugin-keyboard;
cordova plugin add https://github.com/danwilson/google-analytics-plugin.git;
cordova plugin add cordova-plugin-console;
cordova plugin add cordova-plugin-geolocation;
@odra
odra / class-decorator.py
Created February 25, 2016 17:16
add some function in a class instance dictionary within a decorator
# -*- encoding: utf-8 -*-
from functools import wraps
class C(object):
def __init__(self):
self.methods = {}
def method(self, name):
def decorator(fn):
@odra
odra / objectid.js
Last active March 18, 2016 14:42
objectid
function ObjectId () {
this.str = this.genID();
}
ObjectId.prototype.genID = function () {
var float32 = 16777216;
var int16 = 65536;
var ts = Math.floor(Date.now() / 1000).toString(16);
var mid = Math.floor(Math.random() * (int16)).toString(16);
@odra
odra / upload.py
Last active March 13, 2017 20:26
s3 uploader
#!/usr/bin/env python
#./upload.py --key KEY --secret SECRET --bucket BUCKET --path /path/to/file --file /absolute-path-to-upload --mimetype image/png --acl public-read
import argparse
import sys
import boto
parser = argparse.ArgumentParser(description='uploads file to s3')
parser.add_argument('--key', '-k', type=str, required=True, help='s3 auth key')
#!/usr/bin/env python
import importlib
import importlib.util
import pip
def install(name, version=None):
args = [
'install',