- R Markdown
Use a productive notebook interface to weave together narrative text and code to produce elegantly formatted output. Use multiple languages including R, Python, and SQL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Simple Makefile for LaTeX | |
# Author: Lester James V. Miranda | |
# E-mail: [email protected] | |
# Default variables which can be edited via the terminal | |
BUILDDIR = _build | |
COMPILER = pdflatex | |
PROJECT = main | |
BIBLIOGRAPHY = bibliography |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From "Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015" | |
# Bad code | |
import jnettools.toolselements.NetworkElement, \ | |
jnettools.tools.Routing, \ | |
jnettools.tools.RouteInspector | |
ne=jnettools.tools.elements.NetworkElement( '171.0.2.45' ) | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib as hasher | |
import datetime as date | |
# Define what a Snakecoin block is | |
class Block: | |
def __init__(self, index, timestamp, data, previous_hash): | |
self.index = index | |
self.timestamp = timestamp | |
self.data = data | |
self.previous_hash = previous_hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
import re | |
def convert_to(folder, source, timeout=None): | |
args = [libreoffice_exec(), '--headless', '--convert-to', 'pdf', '--outdir', folder, source] | |
process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout) | |
filename = re.search('-> (.*?) using filter', process.stdout.decode()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def crappyhist(a, bins=50, width=140): | |
h, b = np.histogram(a, bins) | |
for i in range (0, bins): | |
print('{:12.5f} | {:{width}s} {}'.format( | |
b[i], | |
'#'*int(width*h[i]/np.amax(h)), | |
h[i], |

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first: mkdir user && cd user && cp /path/to/get_gists.py . | |
# python3 get_gists.py user | |
import requests | |
import sys | |
from subprocess import call | |
user = sys.argv[1] | |
r = requests.get('https://api.github.com/users/{0}/gists'.format(user)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_n_results_dumb(q): | |
r = requests.get('http://www.google.com/search', | |
params={'q': q, | |
"tbs": "li:1"}) | |
r.raise_for_status() | |
soup = bs4.BeautifulSoup(r.text) | |
s = soup.find('div', {'id': 'resultStats'}).text | |
if not s: | |
return 0 | |
m = re.search(r'([0-9,]+)', s) |