Skip to content

Instantly share code, notes, and snippets.

@tsabat
tsabat / zsh.md
Last active October 16, 2024 14:43
Getting oh-my-zsh to work in Ubuntu
@benwah
benwah / mongo_serialize.py
Created June 28, 2012 04:43
Queryset / List of queryset serializer for mongoengine models.
import json
import datetime
from decimal import Decimal
from mongoengine.queryset import queryset_manager
from mongoengine.queryset import QuerySet
from mongoengine.base import BaseList, BaseDict, ObjectId
def list_encoder(inst, obj, field, force_string=False):
"""
@kyledseever
kyledseever / prefix.php
Created June 29, 2012 00:35
Group Strings By Prefix
<?php
// returns the position of the first differing character between
// $left and $right, or -1 if either is empty
function strcmppos($left, $right) {
if (empty($left) || empty($right)) {
return -1;
}
$i = 0;
@boates
boates / testClassificationModel.py
Last active January 16, 2019 01:37
For running sklearn classification algorithms easily on pandas data frame. Also perform tests on model accuracy.
def splitData(df, trainPerc=0.6, cvPerc=0.2, testPerc=0.2):
"""
return: training, cv, test
(as pandas dataframes)
params:
df: pandas dataframe
trainPerc: float | percentage of data for trainin set (default=0.6
cvPerc: float | percentage of data for cross validation set (default=0.2)
testPerc: float | percentage of data for test set (default=0.2)
(trainPerc + cvPerc + testPerc must equal 1.0)
@mjhea0
mjhea0 / 1 - sql_interview_questions.md
Last active June 22, 2024 09:44
Jitbit's SQL interview questions
@meskarune
meskarune / weather.py
Created June 10, 2013 21:54
Get weather data using Wunderground API
python test.py
Traceback (most recent call last):
File "test.py", line 10, in <module>
response = json.load(urllib.request.urlopen(request))
File "/usr/lib/python3.3/json/__init__.py", line 274, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.3/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.3/json/decoder.py", line 352, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
@mplewis
mplewis / flask-uwsgi-nginx-primer.md
Last active September 23, 2024 11:09
Flask + uWSGI + nginx Primer. I've been having trouble with serving a Flask app via uWSGI and nginx, so I thought I'd put together some of the basics to help out others.

Flask + uWSGI + nginx Primer

I've been having trouble with serving a Flask app via uWSGI and nginx, so I thought I'd put together some of the basics to help out others.

How this shit works

  • Flask is managed by uWSGI.
  • uWSGI talks to nginx.
import theano
from pylearn2.models import mlp
from pylearn2.training_algorithms import sgd
from pylearn2.termination_criteria import EpochCounter
from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix
import numpy as np
from random import randint
class XOR(DenseDesignMatrix):
@bsweger
bsweger / useful_pandas_snippets.md
Last active November 13, 2024 19:55
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)

@aneilbaboo
aneilbaboo / virtualenv.rvmrc
Last active October 20, 2015 18:58
This .rvmrc automatically creates/activates a python virtualenv
# save this file in the top level directory of your project as ".rvmrc"
# the virtualenv will be created/activated when you cd into the dir
if hash mkvirtualenv 2>/dev/null; then
virtualenv_name=$(basename `git rev-parse --show-toplevel`)
workon "$virtualenv_name"
if [ "$?" != "0" ]; then
mkvirtualenv "$virtualenv_name"
echo "\"pip install -r requirements.txt\" to install libraries"
fi
fi