Skip to content

Instantly share code, notes, and snippets.

Avatar

Tomek Paczkowski oinopion

View GitHub Profile
View 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 Dec 2, 2016
Use contextmanager to create a decorator
View deco.py
# 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 Oct 5, 2016
How to create read only user in PostgreSQL
View read-access.sql
-- 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;
View books.py
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 Oct 9, 2013
A iterator that converts single sequence into iterable of lists length n.
View iterutils.py
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 Sep 18, 2013
Find all files without unicode_literals import
View nonunicode.sh
grep -iRIL 'unicode_literals' --include '*.py' --exclude '__init__.py'
@oinopion
oinopion / Vagrantfile
Last active Dec 20, 2015
Simple web-dave storage in vagrant
View Vagrantfile
# -*- 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:
View output-bad
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] *********************
View output
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"] *********************
View gchat.go
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")