Skip to content

Instantly share code, notes, and snippets.

View versae's full-sized avatar

Javier de la Rosa versae

View GitHub Profile
@fpillet
fpillet / scale.js
Created May 26, 2011 12:07
Javascript value scaling between two ranges
/* Scale a value from one range to another
* Example of use:
*
* // Convert 33 from a 0-100 range to a 0-65535 range
* var n = scaleValue(33, [0,100], [0,65535]);
*
* // Ranges don't have to be positive
* var n = scaleValue(0, [-50,+50], [0,65535]);
*
* Ranges are defined as arrays of two values, inclusive
@juniorz
juniorz / install_postgis_osx.sh
Created July 14, 2011 03:49
Installing PostGIS on Mac OS X and Ubuntu
# Some good references are:
# http://russbrooks.com/2010/11/25/install-postgresql-9-on-os-x
# http://www.paolocorti.net/2008/01/30/installing-postgis-on-ubuntu/
# http://postgis.refractions.net/documentation/manual-1.5/ch02.html#id2630392
#1. Install PostgreSQL postgis and postgres
brew install postgis
initdb /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
@theladyjaye
theladyjaye / traversals.py
Created February 19, 2012 21:08
Neo4j REST Traversals Approximating embedded syntax for https://github.com/versae/neo4j-rest-client/
# http://docs.neo4j.org/chunked/snapshot/rest-api-traverse.html#rest-api-traversal-returning-nodes-below-a-certain-depth
try:
import simplejson as json
except ImportError:
import json
from neo4jrestclient import client
from neo4jrestclient.request import Request
from neo4jrestclient.request import NotFoundError
@nacx
nacx / __init__.py
Created May 2, 2012 14:15
Pluggable command line tool
import os
# Automatically set the __all__ variable with all
# the available plugins.
plugin_dir = "plugins"
__all__ = []
for filename in os.listdir(plugin_dir):
filename = plugin_dir + "/" + filename
@haplo
haplo / json_encoder.py
Created October 24, 2012 17:10
Custom JSONEncoder
from decimal import Decimal
try:
import simplejson as json
except ImportError:
import json
from django.utils.functional import Promise
class CustomJSONEncoder(json.JSONEncoder):
@diramazioni
diramazioni / pdfimages2txt
Created September 15, 2013 18:17
A script I quickly come up for my needs to extract image from pdf, preprocess and extract text with tesseract
#!/bin/bash
STARTPAGE=2
ENDPAGE=75
SOURCE=book.pdf
OUTPUT=book.txt
RESOLUTION=600
LAYOUT="1"
[[ -e out.txt ]] && rm out.txt
for i in `seq $STARTPAGE $ENDPAGE`; do
@jdmaturen
jdmaturen / sbg.py
Last active May 1, 2020 19:43
Implementation of the shifted beta geometric (sBG) model from "How to Project Customer Retention" (Fader and Hardie 2006) http://www.brucehardie.com/papers/021/sbg_2006-05-30.pdf Apache 2 License
"""
Implementation of the shifted beta geometric (sBG) model from "How to Project Customer Retention" (Fader and Hardie 2006)
http://www.brucehardie.com/papers/021/sbg_2006-05-30.pdf
Apache 2 License
"""
from math import log
@jdmaturen
jdmaturen / bg_nbd.py
Created October 16, 2013 05:36
Implementation of the beta-geometric/NBD (BG/NBD) model from '"Counting Your Customers" the Easy Way: An Alternative to the Pareto/NBD Model' (Fader, Hardie and Lee 2005) http://brucehardie.com/papers/018/fader_et_al_mksc_05.pdf and accompanying technical note http://www.brucehardie.com/notes/004/
"""
Implementation of the beta-geometric/NBD (BG/NBD) model from '"Counting Your Customers" the Easy Way: An Alternative to
the Pareto/NBD Model' (Fader, Hardie and Lee 2005) http://brucehardie.com/papers/018/fader_et_al_mksc_05.pdf and
accompanying technical note http://www.brucehardie.com/notes/004/
Apache 2 License
"""
from math import log, exp
import numpy as np
@maxwelleite
maxwelleite / ttf-vista-fonts-installer.sh
Last active July 10, 2024 18:25
Script to install Microsoft Vista TrueType Fonts (TTF) aka Microsoft’s ClearType fonts on Ubuntu distros
#!/bin/bash
# Author: Maxwel Leite
# Website: http://needforbits.wordpress.com/
# Description: Script to install Microsoft Vista TrueType Fonts (TTF) aka Microsoft’s ClearType fonts on Ubuntu distros
# Microsoft added a group of new "ClearType Fonts" to Windows with Windows Vista and Office 2007.
# These fonts are named Constantia, Corbel, Calibri, Cambria (and Cambria Math), Candara, and Consolas.
# Calibri became the default font on Microsoft Word 2007, and it’s still the default font on Word 2016 today.
# Dependencies: wget, fontforge and cabextract
# Note: Microsoft no longer provides the PowerPoint Viewer 2007 (v12.0.4518.1014) or any version anymore for download
# Tested: Ubuntu Saucy/Trusty/Xenial/Bionic
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 19, 2024 18:04
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)