Skip to content

Instantly share code, notes, and snippets.

View dbrgn's full-sized avatar

Danilo Bargen dbrgn

View GitHub Profile
@dbrgn
dbrgn / create_django_session.py
Last active August 12, 2024 04:27
Manually create a Django session
from django.contrib import auth
from django.contrib.sessions.backends.db import SessionStore
session = SessionStore(None)
session.clear()
session.cycle_key()
session[auth.SESSION_KEY] = user._meta.pk.value_to_string(user)
session[auth.BACKEND_SESSION_KEY] = 'django.contrib.auth.backends.ModelBackend'
session[auth.HASH_SESSION_KEY] = user.get_session_auth_hash()
session.save()
@dbrgn
dbrgn / app.js
Created January 6, 2016 12:51
Angular Demo
var app = angular.module('demoApp', []);
app.factory('numberFactory', function() {
var number = 0;
return function() {
number += 1;
return number;
};
});
@dbrgn
dbrgn / iterator.rs
Last active December 29, 2015 09:12
struct Tokenizer<R: BufRead> {
reader: R,
current_line: String,
}
impl<R> Iterator for Tokenizer<R> where R: BufRead {
type Item = &'a str;
fn next<'a>(&'a mut self) -> Option<&'a str> {
self.current_line.clear();
let bytes_read = self.reader.read_line(&mut self.current_line).unwrap();
TASK: [edxapp | syncdb and migrate] *******************************************
failed: [52.19.185.231] => (item=lms) => {"changed": true, "cmd": ["/edx/bin/edxapp-syncdb-lms"], "delta": "0:00:19.840901", "end": "2015-08-27 09:15:08.920340", "item": "lms", "rc": 1, "start": "2015-08-27 09:14:49.079439", "warnings": []}
stderr: warning: unable to access '/root/.config/git/attributes': Permission denied
2015-08-27 05:14:50,577 INFO 21831 [dd.dogapi] dog_stats_api.py:66 - Initializing dog api to use statsd: localhost, 8125
FATAL ERROR - The following SQL query failed: alter table `auth_user` drop `website`, drop `about`, drop `gold`, drop `email_isvalid`, drop `real_name`, drop `location`, drop `reputation`, drop `gravatar`, drop `bronze`, drop `last_seen`, drop `silver`, drop `questions_per_page`, drop `new_response_count`, drop `seen_response_count`;
The error was: (1091, "Can't DROP 'website'; check that column/key exists")
FATAL ERROR - The following SQL query failed: DROP INDEX `student_testcenterregistrat
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import, unicode_literals
import re
from itertools import izip
import six
from rest_framework.filters import DjangoFilterBackend
from rest_framework.compat import django_filters
fn divisors<T : Add + Div + Rem>(number: T) -> Iterator<Item=T> {
(2..number/2+1).filter(|&x| number % x == 0)
}
@dbrgn
dbrgn / neopixelring.c.diff
Created December 18, 2014 23:47
Crazyflie 2.0 LED ring: Battery charge indicator
diff --git a/modules/src/neopixelring.c b/modules/src/neopixelring.c
index c01cae7..a1cc722 100644
--- a/modules/src/neopixelring.c
+++ b/modules/src/neopixelring.c
@@ -72,8 +72,10 @@
#define LIMIT(a) ((a>255)?255:(a<0)?0:a)
#define SIGN(a) ((a>=0)?1:-1)
#define DEADBAND(a, b) ((a<b) ? 0:a)
+#define LINSCALE(domain_low, domain_high, codomain_low, codomain_high, value) ((codomain_high - codomain_low) / (domain_high - domain_low)) * (value - domain_low) + codomain_low
@dbrgn
dbrgn / gist:cf30e2524ea21d80c853
Last active December 11, 2021 05:08
PostgreSQL Backup Script
#!/bin/bash
TIMESTAMP=$(date +\%Y\%m\%d_\%H\%M\%S)
DEST=/var/backups/db/
OWNER=backuppc
GROUP=backuppc
echo -n "Creating temp dir..."
TMPDIR=$(mktemp -d)
echo " Done."
$ python2 bin/cfclient -d debug
DEBUG:cfclient.cfclient:Using config path /mnt/data/Projects/crazyflie-clients-python/lib/../conf
DEBUG:cfclient.cfclient:sys.path=['/mnt/data/Projects/crazyflie-clients-python/lib', '/mnt/data/Projects/crazyflie-clients-python/lib/../conf', '/mnt/data/Projects/crazyflie-clients-python/bin', '/home/danilo/.virtualenvs/pdb4qt/lib/python27.zip', '/home/danilo/.virtualenvs/pdb4qt/lib/python2.7', '/home/danilo/.virtualenvs/pdb4qt/lib/python2.7/plat-linux2', '/home/danilo/.virtualenvs/pdb4qt/lib/python2.7/lib-tk', '/home/danilo/.virtualenvs/pdb4qt/lib/python2.7/lib-old', '/home/danilo/.virtualenvs/pdb4qt/lib/python2.7/lib-dynload', '/usr/lib64/python2.7', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib/python2.7/lib-tk', '/home/danilo/.virtualenvs/pdb4qt/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages/wx-3.0-gtk2']
INFO:cfclient.cfclient:Di
@pytest.fixture(scope='session')
def server(request):
"""
Fixture that provides a bottle server running in a background thread.
"""
class StoppableServer(bottle.ServerAdapter):
server = None
def run(self, handler):
self.server = make_server(self.host, self.port, handler, **self.options)