Skip to content

Instantly share code, notes, and snippets.

View bolshoibooze's full-sized avatar

Arthur Mwai bolshoibooze

View GitHub Profile
#
# CONFIGURATION FOR USING SMS KANNEL WITH RAPIDSMS
#
# For any modifications to this file, see Kannel User Guide
# If that does not help, see Kannel web page (http://www.kannel.org) and
# various online help and mailing list archives
#
# Notes on those who base their configuration on this:
# 1) check security issues! (allowed IPs, passwords and ports)
# 2) groups cannot have empty rows inside them!
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from pyExcelerator import *
def export_as_xls(modeladmin, request, queryset):
"""
Generic xls export admin action.
usage:actions = [export_as_xls]
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
@bolshoibooze
bolshoibooze / gist:17adacf7436783faba3c
Created July 13, 2015 06:06
Built-in XML android layouts(typically used in Adaptors)
//simple_list_item_1
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/listItemFirstLineStyle"
android:paddingTop="2dip"
android:paddingBottom="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
//simple_list_item_2
#One of those handy scripts, see:http://djangotricks.blogspot.co.ke/2013/12/how-to-export-data-as-excel.html
from .models import *
from django.http import *
"""
# Quick 'how-to' guide
# model in question
class Duplicate(models.Model):
import urllib2
"""
#Usage:
in a python shell
>> import get_pepperstone_data
>> get_pepperstone_data.run()
# Notes:
1: Selection of pairs is highly opinionated
@bolshoibooze
bolshoibooze / useful_pandas_snippets.py
Created October 10, 2015 18:21 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]
@bolshoibooze
bolshoibooze / note.md
Created October 14, 2015 10:48 — forked from fyears/note.md
how to install scipy numpy matplotlib ipython in virtualenv

if you are using linux, unix, os x:

pip install -U setuptools
pip install -U pip

pip install numpy
pip install scipy
pip install matplotlib
#pip install PySide
@bolshoibooze
bolshoibooze / Python concave hull ( alpha shape ) .md
Created October 15, 2015 13:12 — forked from hellpanderrr/Python concave hull ( alpha shape ) .md
Concave hull in python using scipy and networkx
from scipy.spatial import Delaunay
import networkx as nx
 
points = [ [0,0],[0,50],[50,50],[50,0],[0,400],[0,450],[50,400],[50,450],[700,300],[700,350],[750,300],[750,350],
          [900,600],[950,650],[950,600],[900,650]
]
def concave(points,alpha_x=150,alpha_y=250):
  points = [(i[0],i[1]) if type(i) <> tuple else i for i in points]
  de = Delaunay(points)
@bolshoibooze
bolshoibooze / rank_metrics.py
Created December 6, 2015 22:05 — forked from bwhite/rank_metrics.py
Ranking Metrics
"""Information Retrieval metrics
Useful Resources:
http://www.cs.utexas.edu/~mooney/ir-course/slides/Evaluation.ppt
http://www.nii.ac.jp/TechReports/05-014E.pdf
http://www.stanford.edu/class/cs276/handouts/EvaluationNew-handout-6-per.pdf
http://hal.archives-ouvertes.fr/docs/00/72/67/60/PDF/07-busa-fekete.pdf
Learning to Rank for Information Retrieval (Tie-Yan Liu)
"""
import numpy as np