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
rm -f out | |
mkfifo out | |
trap "rm -f out" EXIT | |
while true | |
do | |
cat out | nc -w1 -l 1500 > >( # parse the netcat output, to build the answer redirected to the pipe "out". | |
export REQUEST= | |
while read line | |
do | |
line=$(echo "$line" | tr -d '[\r\n]') |
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
Install pyenv on Ubuntu 18.04 + fish shell | |
- Install the packages required to compile Python | |
$ sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev | |
- Download pyenv code from github | |
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv | |
- Define environment variable PYENV_ROOT to point to the path where pyenv repo is cloned | |
$ echo "set --export PYENV_ROOT $HOME/.pyenv" > ~/.config/fish/conf.d/pyenv.fish |
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
# This is just a cheat sheet: | |
# On production | |
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz | |
# On local | |
scp -C production:~/database.sql.gz | |
dropdb database && createdb database | |
gunzip < database.sql.gz | psql database |
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
#!/bin/sh | |
# option 2: paste this into user-data to automate install via boot script | |
# NOTE: update --label=owner=YOURNAME below if you want to easily identify yours | |
# renames the host to have a suffix of alexellisio | |
export original=$(cat /etc/hostname) | |
sudo hostname $original-master-alexellisio | |
echo $original-master-alexellisio | sudo tee /etc/hostname | |
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D |
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
#!/usr/bin/env python | |
# import csv | |
# reader = csv.reader(open('4956984.csv', 'rb')) | |
def gen_chunks(reader, chunksize=100): | |
""" | |
Chunk generator. Take a CSV `reader` and yield | |
`chunksize` sized slices. | |
""" |
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 django.core.paginator import EmptyPage, PageNotAnInteger, Paginator | |
# First we create a little helper function, becase we will potentially have many PaginatedTypes | |
# and we will potentially want to turn many querysets into paginated results: | |
def get_paginator(qs, page_size, page, paginated_type, **kwargs): | |
p = Paginator(qs, page_size) | |
try: | |
page_obj = p.page(page) | |
except PageNotAnInteger: |
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 os | |
import base64 | |
import flask | |
import urllib.parse | |
import requests | |
app = flask.Flask(__name__) | |
APP_ID = "ID" | |
APP_SECRET = "SECRET" |
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, urllib, urllib2, cookielib | |
class FacebookLogin(object): | |
def __init__(self,user,passw): | |
self.user=user | |
self.passw=passw | |
self.browser = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) | |
self.browser.addheaders=[('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0')] | |
urllib2.install_opener(self.browser) |
NewerOlder