Skip to content

Instantly share code, notes, and snippets.

View adrianp's full-sized avatar
💀
Hey there! I am using WhatsApp.

Adrian-Tudor Panescu adrianp

💀
Hey there! I am using WhatsApp.
View GitHub Profile
@adrianp
adrianp / Scheduled tasks with Celery in Django
Created March 10, 2011 18:58
Installing django-celery and adding scheduled tasks to a Django project
THESE INSTRUCTIONS ARE FOR OLD VERSIONS OF DJANGO/CELERY/PYTHON!
1. Download the latest version of django-celery from here:
https://github.com/ask/django-celery/archives/master
2. Unzip, go to folder
3. python setupy.py build
4. python setup.py install
@adrianp
adrianp / gist:949750
Created April 30, 2011 15:29
Java implementation of Aitken's Algorithm (scheme) for determining Newton's Divided Diffences
/**
*
* @param x the array of abscissae
* @param y the array of ordinates
* @return the top elements of the Divided Difference Table used when
* calculating Newton's Devided Differences
*/
public static double[] aitken(double[] x, double[] y) {
int n = x.length;
double[] dividedDifferences = y.clone();
@adrianp
adrianp / setattr_example.py
Created January 14, 2012 14:58
Example of how to dynamically add new attributes to an instance of a class (an object) in Python using setattr()
class MyClass:
def __init__(self, a_number, **kwargs):
self.a_number = a_number
for key, value in kwargs.items(): # adding new attributes
setattr(self, key, value)
if __name__ == "__main__":
MY_OBJECT = MyClass(1, a_string = "Hello world!")
print MY_OBJECT.a_number, MY_OBJECT.a_string
@adrianp
adrianp / parse.py
Created February 10, 2012 17:54
Recursevly parsing an XML in Python 3 using ElementTree
"""To run this: $ python3 parse.py test.xml
The script will pase a XML file and print its node tags.
Compatible with Python 3; changing the print statements should make this
compatible with Python 2.
"""
import sys
@adrianp
adrianp / embedly.py
Created February 10, 2012 18:34
Embedly Challenge
"""These are my answers for the Embedly Challenge"""
from xml.etree import ElementTree
from numpy import std # you'll need numpy for Question 2
def question1():
def digitSum(x):
# pretty ugly, eh?
return sum(map(int, list(str(x))))
@adrianp
adrianp / compare.py
Last active October 1, 2015 01:28
Comparing a list with a function in Python
"""Some Python code to illustrate the 'issue' noticed in JavaScript here:
http://stackoverflow.com/questions/9381321/a-function-is-larger-than-an-array
This will work on Python 2.x; in Python 3.x you would get:
TypeError: unorderable types: list() > function()
"""
l1 = []
def f():
@adrianp
adrianp / true_false.py
Created March 8, 2012 17:48
True = False in Python
# A funny thing about Python: http://hatepaste.com/paste/6c7e1a3c
True = False
if True:
print "ORLY?"
else:
print "YARLY!"
# BUT, this will work only in Python 2.x; in Python 3.x you will get
# "SyntaxError: assignment to keyword" at line 2
@adrianp
adrianp / copy.py
Created March 21, 2012 20:06
How to initialize arrays and copy objects the right way in Python
"""
This brief script demonstrates a frequent mistake in Python related
to the different ways of copying objects.
References:
1. Personal experience
2. http://stackoverflow.com/questions/2196956/add-an-object-to-an-array-python
"""
import copy # http://docs.python.org/library/copy.html
For compiling LaTeX documents (with BibTex support) we basically have two options:
LaTeX - will produce a DVI file:
latex -interaction=nonstopmode -shell-escape %.tex|bibtex %.aux|latex -interaction=nonstopmode -shell-escape %.tex|latex -interaction=nonstopmode -shell-escape %.tex|"C:/Program Files (x86)/MiKTeX 2.9/miktex/bin/yap.exe" %.dvi
PdfLaTeX:
pdflatex --shell-escape --enable-write18 -synctex=1 -interaction=nonstopmode %.tex|bibtex %.aux|pdflatex --shell-escape --enable-write18 -synctex=1 -interaction=nonstopmode %.tex|pdflatex --shell-escape --enable-write18 -synctex=1 -interaction=nonstopmode %.tex|"C:/Program Files (x86)/Adobe/Reader 11.0/Reader/AcroRd32.exe" %.pdf
These commands are tailored for Texmaker (Win) and will open the approiate preview application after compiling the documents.
Also, (E)PS file support is included; to make sure such images will be correctly displayed, add the following to your LaTeX source preamble:
@adrianp
adrianp / Big List of Big Data
Last active December 15, 2015 20:19
Lean list of various BigData/NoSQL related projects
This work-in-progress summarizes the way-too-many BigData(tm) technologies.
This is by no means an in-depth description, but a very short summary so that
I know where to look.
1. Databases:
* DynamoDB - aws.amazon.com/dynamodb/ - Amazon AWS integration, MapReduce
* MongoDB - mongodb.org/ - JSON-style document database, SQL-like queries + MapReduce
* Riak - basho.com/riak/ - Key-Value storage, MapReduce
* CouchDB - couchdb.apache.org/ - JSON document storage, JavaScript Queries + MapReduce