Skip to content

Instantly share code, notes, and snippets.

View drdaeman's full-sized avatar
😺
I love cats

Aleksei Zhukov drdaeman

😺
I love cats
View GitHub Profile
@drdaeman
drdaeman / ppp_generic.patch
Last active August 29, 2015 14:02
An somewhat ugly hack to make packets to certain IPv4 addresses not increment interface counters. Original patch's not mine.
--- drivers/net/ppp/ppp_generic.c 2014-01-20 06:40:07.000000000 +0400
+++ drivers/net/ppp/ppp_generic.c 2014-06-09 14:48:48.000000000 +0400
@@ -54,6 +54,13 @@
#include <net/net_namespace.h>
#include <net/netns/generic.h>
+#define CONFIG_PPP_FILTER_COUNTERS 1
+
+#ifdef CONFIG_PPP_FILTER_COUNTERS
+#include <linux/proc_fs.h>
@drdaeman
drdaeman / test_v4mapped.c
Created March 25, 2011 15:30
Possibly weird getaddrinfo() behavior
#include <netdb.h>
#include <stdio.h>
#include <string.h>
int main(void) {
struct addrinfo hints, *ai;
char buf[INET6_ADDRSTRLEN];
int ret;
/*
@drdaeman
drdaeman / node-postgres_types_bytea.fragment.js
Created July 19, 2011 18:38
Support for bytea datatype for node-postgres
// types.js
// ...
var parseByteA = function(val) {
// Step 1: Find binary data length (and validate data)
var length = 0;
for (var i = 0; i < val.length; i++) {
if (val[i] == "\\") {
if (i >= val.length - 1)
throw "Invalid bytea encoding: '\\' at the end";
@drdaeman
drdaeman / 0001-no-reply-wo-explicit-servicename.patch
Created February 17, 2012 03:47
rp-pppoe service-name related patches
--- rp-pppoe-3.8/src/pppoe-server.c 2010-07-15 16:42:39.031057949 +0400
+++ rp-pppoe-3.8/src/pppoe-server.c 2010-07-15 16:48:14.078605821 +0400
@@ -97,6 +97,7 @@
#define MAX_SERVICE_NAMES 64
static int NumServiceNames = 0;
static char const *ServiceNames[MAX_SERVICE_NAMES];
+static int ReactionOnNoServiceName = 1;
PppoeSessionFunctionTable DefaultSessionFunctionTable = {
PppoeStopSession,
@drdaeman
drdaeman / capt
Created August 24, 2012 20:44
Simple CUPS backend wrapper for Canon LBP-810 and LBP-1120 FOSS driver
#!/bin/sh
# What's this
# -----------
# CUPS backend wrapper for Canon LBP-810 and LBP-1120 FOSS driver.
# Works for me with LBP-1120 on Ubuntu 12.04.
#
# Because I don't want a kludge with dummy serial:/dev/ttyS0 backend,
# as everyone on the 'net seem to suggest. That never worked for me.
# Nor I want to use Canon proprietary ccpd daemon, which frequently
@drdaeman
drdaeman / melt_mt10t7-7_example.ino
Created November 26, 2012 12:44
Arduino + ЖКИ МЭЛТ МТ10Т7-7
/* Example: MELT MT10T7-7 LCD display, directly connected to Arduino.
* Display datasheet: http://www.melt.com.ru/docs/MT-10T7_8_9.pdf
*/
// Other pins: GND to GND; +E to 5V; V0, +L and -L are not necessary for example purposes.
#define PIN_WR1 3
#define PIN_WR2 2
#define PIN_A0 13
#define PIN_DB0 9
#define PIN_DB1 10
@drdaeman
drdaeman / form_fixes.py
Last active March 10, 2016 14:05
Quick-and-dirty fix for forms using ModelChoiceField with to_field_name set.
# Quick-and-dirty fix for forms using ModelChoiceField with to_field_name set.
# See https://code.djangoproject.com/ticket/20202 for details.
# Example usage:
# >>> import form_fixes
# >>> form_fixes.fix_to_field_name()
from django import forms
from django.db import models
"""
A drop-in replacement to make PyBrowserID[1]
use cryptography.io instead of M2Crypto.
Replace browserid/crypto/fallback.py with this file,
or monkey-patch browserid.crypto.{Key,RSKey,DSKey},
or whatever. The choice of dirtiness is up to you.
Use with caution. I'm no cryptographer.

Keybase proof

I hereby claim:

  • I am drdaeman on github.
  • I am drdaeman (https://keybase.io/drdaeman) on keybase.
  • I have a public key whose fingerprint is FE74 8B15 6F78 F2B3 360E 9C85 E1C3 A285 7EFC 7C66

To claim this, I am signing this object:

@drdaeman
drdaeman / fields.py
Last active May 12, 2016 20:34
Experiment with django-money to have multiple money fields that share the single currency. May contain bugs, use with extreme caution.
from __future__ import absolute_import, unicode_literals
from djmoney.models.fields import MoneyField, MoneyFieldProxy
class CurrencyLockedMoneyFieldProxy(MoneyFieldProxy):
def __init__(self, field, currency_field_name=None):
super(CurrencyLockedMoneyFieldProxy, self).__init__(field)
if currency_field_name is not None:
self.currency_field_name = currency_field_name