Skip to content

Instantly share code, notes, and snippets.

@stalkerg
stalkerg / s3.py
Created January 12, 2015 13:09
Async Tornado S3 uploader with AWS4 sign
import hashlib
import hmac
import mimetypes
import binascii
from calendar import timegm
from datetime import datetime
import time
from email.utils import formatdate
from urllib.parse import quote, urlparse
@drgarcia1986
drgarcia1986 / __main__.py
Last active August 9, 2023 21:20
Example of OAuth2 autentication server with Client Credentials grant (using python-oauth2 and tornado)
# !/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Diego Garcia'
import tornado.web
import tornado.ioloop
import oauth2.tokengenerator
import oauth2.grant
import oauth2.store.redisdb
import oauth2.store.mongodb
@app.route('/login/<provider_name>', methods=['GET', 'POST'])
@authomatic.login('g')
@requires_ssl
def login(provider_name):
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('index'))
if authomatic.result:
if authomatic.result.error:
return 'Something went wrong: {0}'.format(authomatic.result.error.message)
if authomatic.result.user:
@peterklipfel
peterklipfel / spark_master.sh
Last active November 24, 2015 19:38
install spark ubuntu 14.04
sudo apt-get update
sudo apt-get install -y openjdk-7-jdk
sudo su -c 'echo "JAVA_HOME=\"/usr/lib/jvm/java-7-openjdk-amd64\"" >> /etc/environment'
cd /opt
sudo wget http://d3kbcqa49mib13.cloudfront.net/spark-1.0.1-bin-hadoop2.tgz
sudo tar -zxf spark-1.0.1-bin-hadoop2.tgz
cd spark-1.0.1-bin-hadoop2
# assumes that hostname is set correctly, and the main interface is on eth0, add HOSTNAME to /etc/hosts
sudo su -c "echo `ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'` `cat /etc/hostname` >> /etc/hosts"
sbin/start-master.sh
@gitaarik
gitaarik / git_submodules.md
Last active May 10, 2024 05:09
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of usecases of submodules:

  • Separate big codebases into multiple repositories.
@jiphex
jiphex / apple-bluetooth-kb-f20.md
Last active February 14, 2023 13:58
Pairing an Apple Bluetooth keyboard with Fedora 20

For some reason, this didn't work with the standard GUI bluetooth tools, so I did the following

  1. Run the command-line bluetoothctl tool
  2. type "agent on"
  3. type "scan on"
  4. press the button on your keyboard, the light should flash if it's not paired with anything else
  5. type "devices" (this shows the list of devices)
  6. type "trust xxxx" where xxxx is the keyboard MAC
  7. type "connect xxxx" where xxxx is the keyboard MAC
  8. type "pair xxxx" where xxxx is the keyboard MAC
@higarmi
higarmi / Flatten JSON or a nested dictionary
Created September 26, 2013 01:49
This python recursive function flattens a JSON file or a dictionary with nested lists and/or dictionaries. The output is a flattened dictionary that use dot-chained names for keys, based on the dictionary structure. This allows for reconstructing the JSON structure or converting it to other formats without loosing any structural information.
"""
example: The following JSON document:
{"maps":[{"id1":"blabla","iscategorical1":"0", "perro":[{"dog1": "1", "dog2": "2"}]},{"id2":"blabla","iscategorical2":"0"}],
"masks":{"id":"valore"},
"om_points":"value",
"parameters":{"id":"valore"}}
will have the following output:
{'masks.id': 'valore', 'maps.iscategorical2': '0', 'om_points': 'value', 'maps.iscategorical1': '0',
'maps.id1': 'blabla', 'parameters.id': 'valore', 'maps.perro.dog2': '2', 'maps.perro.dog1': '1', 'maps.id2': 'blabla'}
@dustinmm80
dustinmm80 / multivm_vagrant_dry.md
Created September 15, 2013 04:48
An example of how to write Vagrantfiles following the DRY principle.
=begin
Example box JSON schema
{
    :name => :name_of_vagrant_box, #REQUIRED
    :ip => '10.0.0.11', #REQUIRED
    :synced_folders => [
        { '.' => '/home/vagrant/myapp' }
    ],
    :commands => [
@miku
miku / csvprocessor.py
Last active July 22, 2019 15:02
CSV processor examples for luigi. Can serialize *args to CSV. Can deserialize CSV rows into namedtuples if requested. -- "works on my machine".
from luigi.format import Format
import csvkit
class CSVOutputProcessor(object):
"""
A simple CSV output processor to be hooked into Format's
`pipe_writer`.
If `cols` are given, the names are used as CSV header, otherwise no
explicit header is written.
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: