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 / citeproc-py_example.py
Last active August 18, 2017 12:56
Minimal citeproc-py example
# https://github.com/brechtm/citeproc-py
# https://github.com/citation-style-language/styles
from citeproc.py2compat import *
from citeproc import formatter, Citation, CitationItem, CitationStylesStyle, CitationStylesBibliography
from citeproc.source.json import CiteProcJSON
def get_citation(data, style):
bib_source = CiteProcJSON(data)
@adrianp
adrianp / 40-libinput.conf
Last active January 8, 2023 08:39
Enable scroll for the Logitech Trackman Marble mouse on Ubuntu 17.04
# The lines below go into: /usr/share/X11/xorg.conf.d/40-libinput.conf
# Last tested on Ubuntu 18.04 on 13.08.2018
#
# Enable scroll wheel emulation for the Logitech Trackman Marble mouse. Holding
# the small right button will allow you to scroll both vertically and
# horizontally using the ball; for using the left small button use 8 for
# ScrollButton.
# Source: https://wiki.archlinux.org/index.php/Logitech_Marble_Mouse#Using_libinput
# This config also disables the browser back/forward functionality of the small buttons
# and is intended for left-hand users.
@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
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 / 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
@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 / 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 / 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 / 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 / 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