Skip to content

Instantly share code, notes, and snippets.

View dbrgn's full-sized avatar

Danilo Bargen dbrgn

View GitHub Profile
import requests
s = requests.Session()
pool_32_adapter = requests.adapters.HTTPAdapter(pool_connections=1, pool_maxsize=32)
s.mount('http://', pool_32_adapter)
s.mount('https://', pool_32_adapter)
@dbrgn
dbrgn / 1_server.c
Last active December 11, 2015 22:28
Example of a very simple server and client that communicate via named pipes.
#include <stdio.h> // printf, fflush, stdout
#include <fcntl.h> // open, O_RDWR
#include <stdlib.h> // exit
#include <signal.h> // signal, SIGINT
#include <sys/stat.h> // mkfifo
#include <unistd.h> // read
#define QUEUE "request_queue"
#define BUFLEN 20
@dbrgn
dbrgn / export.py
Created February 10, 2013 11:44
Memonic export script
"""
Dump item and set data from memonic into .json files.
Please issue ``mkdir -p data/{sets,items}`` before running the script.
"""
from __future__ import print_function, division, absolute_import, unicode_literals
import json
import requests
API_KEY = '<api-key>'
API_URL = 'https://api.memonic.com/v2/'
def is_owner_or_readonly(fieldname='owner'):
"""Function to generate a permission class that checks whether the current
user is the owner according to the specified field name."""
class IsOwnerOrReadOnly(permissions.BasePermission):
"""Only allow owners of an object to edit it."""
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
[2013-05-24 21:42:28,507: ERROR/MainProcess] Task celery.chord[fcff074e-692c-4c9b-8014-98a8a5bf4988] raised exception: AttributeError("'dict' object has no attribute 'type'",)
Traceback (most recent call last):
File "/home/danilo/.virtualenvs/radar/lib/python2.7/site-packages/celery/task/trace.py", line 228, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/danilo/.virtualenvs/radar/lib/python2.7/site-packages/celery/task/trace.py", line 415, in __protected_call__
return self.run(*args, **kwargs)
File "/home/danilo/.virtualenvs/radar/lib/python2.7/site-packages/celery/app/builtins.py", line 336, in run
return header(*partial_args, **{'task_id': group_id})
File "/home/danilo/.virtualenvs/radar/lib/python2.7/site-packages/celery/canvas.py", line 406, in __call__
type = tasks[0].type.app.tasks[self['task']]
@dbrgn
dbrgn / gist:6078106
Created July 25, 2013 09:13
google geekweek
from functools import partial
hexint = partial(int, base=16)
code = '53 65 61 72 63 68 20 59 6f 75 54 75 62 65 20 66 6f 72 20 2f 20 67 65 65 6b 77 65 65 6b'
numbers = map(hexint, code.split())
print ''.join(map(chr, numbers))
@dbrgn
dbrgn / gist:6078111
Created July 25, 2013 09:15
Shorter / less clean version of geekweek
code = '53 65 61 72 63 68 20 59 6f 75 54 75 62 65 20 66 6f 72 20 2f 20 67 65 65 6b 77 65 65 6b'
print ''.join(map(chr, [int(val, base=16) for val in code.split()]))
# Social auth
AUTHENTICATION_BACKENDS = ('social_auth.backends.google.GoogleOAuth2Backend',)
LOGIN_URL = '/auth/login/'
LOGIN_REDIRECT_URL = '/'
LOGIN_ERROR_URL = '/auth/login-error/'
GOOGLE_OAUTH2_CLIENT_ID = require_env('GOOGLE_OAUTH2_CLIENT_ID')
GOOGLE_OAUTH2_CLIENT_SECRET = require_env('GOOGLE_OAUTH2_CLIENT_SECRET')
GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS = {'access_type': 'offline'}
GOOGLE_OAUTH_EXTRA_SCOPE = [
'https://adwords.google.com/api/adwords',
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dbrgn
dbrgn / gist:7451806
Last active December 28, 2015 05:39
Fetch current bitcoin prices with Go.
package main
import (
"fmt"
"net/http"
"io/ioutil"
"encoding/json"
)
const baseUrl = "http://data.mtgox.com/api/2/%s/money/ticker"