Skip to content

Instantly share code, notes, and snippets.

View oinopion's full-sized avatar

Tomek Paczkowski oinopion

View GitHub Profile
@oinopion
oinopion / keybase.md
Created February 13, 2017 16:39
keybase.md

Keybase proof

I hereby claim:

  • I am oinopion on github.
  • I am oinopion (https://keybase.io/oinopion) on keybase.
  • I have a public key ASBxi5CUEoLSH6wms2YYL3bjYNdlnJeMPewkFUAyGHtttgo

To claim this, I am signing this object:

@oinopion
oinopion / deco.py
Last active December 2, 2016 08:08
Use contextmanager to create a decorator
# Read docs here: https://docs.python.org/3/library/contextlib.html
>>> from contextlib import contextmanager
>>>
>>>
>>> @contextmanager
... def deco_and_cm():
... print('Hello')
... yield
... print('Goodbye')
...
@oinopion
oinopion / read-access.sql
Created October 5, 2016 13:00
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@oinopion
oinopion / books.py
Created February 15, 2014 18:52
Random PR
import json
import random
closeds = json.load(open('closed.json'))
opens = json.load(open('open.json'))
def today(pr):
return pr['created_at'].startswith('2014-02-15')
prs = [p for p in (opens+closeds) if today(p)]
@oinopion
oinopion / iterutils.py
Created October 9, 2013 09:11
A iterator that converts single sequence into iterable of lists length n.
def in_batches(sequence, n=2):
"""
>>> list(in_batches([1, 2, 3, 4, 5], n=2))
[[1, 2], [3, 4], [5, None]]
"""
iterable = iter(sequence)
try:
while True:
values = [None] * n
for i in xrange(n):
@oinopion
oinopion / nonunicode.sh
Created September 18, 2013 13:18
Find all files without unicode_literals import
grep -iRIL 'unicode_literals' --include '*.py' --exclude '__init__.py'
@oinopion
oinopion / Vagrantfile
Last active December 20, 2015 16:19
Simple web-dave storage in vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Run 'vagrant up' to start server
# Apache will be available at localhost:8000
# Nginx will be available at localhost:7000
# Both share htpass and data directory
# To upload file via PUT do:
# $ curl 'http://vagrant:vagrant@localhost:8000/hello.txt' -T hello.txt
# To create collection do:
TASK: [aasdfasds] *********************
ok: [192.168.60.2] => {"msg": "$home/13-02-17--19-36-28"}
TASK: [pause seconds=2] *********************
(^C-c = continue early, ^C-a = abort)
[192.168.60.2]
Pausing for 2 seconds
ok: [192.168.60.2] => {"changed": false, "delta": 2, "rc": 0, "start": "2013-02-17 19:36:28.635563", "stderr": "", "stdout": "Paused for 2.0 seconds", "stop": "2013-02-17 19:36:30.635935"}
TASK: [aasdfasd] *********************
@oinopion
oinopion / output
Last active December 13, 2015 20:38
TASK: [debug msg="/home/$user/13-02-17--15-23-58"] *********************
ok: [192.168.60.2]
TASK: [pause seconds=5] *********************
(^C-c = continue early, ^C-a = abort)
[192.168.60.2]
Pausing for 5 seconds
ok: [192.168.60.2]
TASK: [debug msg="/home/$user/13-02-17--15-24-04"] *********************
package gchat
import "log"
import "net"
import "bufio"
import "fmt"
func Serve() {
fmt.Println("Start server on port 2000")
l, err := net.Listen("tcp", ":2000")