Skip to content

Instantly share code, notes, and snippets.

@aniline
aniline / goog_totp.py
Created September 12, 2017 17:51
TOTP like Google Authenticator
import hashlib, hmac, base64, struct, time, math
def GoogleTOTP(s):
msg = int(math.floor(time.time()/30))
hm = hmac.new(base64.b32decode(s), struct.pack('>q', msg), hashlib.sha1).digest()
offs = ord(hm[-1]) & 0xF
code = str(((struct.unpack('>L',hm[offs:offs+4])[0]) & 0x7FFFFFFF) % 1000000).zfill(6)
return code
print GoogleTOTP("")
@aniline
aniline / readclip.py
Created August 7, 2017 06:41
An old script (better here than in Dropbox, dunno what it does).
#!python
import RPi.GPIO as GPIO
import time
import sys
GPIO.setmode(GPIO.BOARD)
bint = 3
@aniline
aniline / lfsr.py
Created March 12, 2017 11:41
Some trials with lfsr.
#!/usr/bin/env python
import sys, time
id = 1234567890
lfsr = 0xDEADBEEF
def lfsrN(lfsr, count):
#0b10101010101
#0x80000417, 0b10000000 00000000 0000 0100 0001 0111
#!/usr/bin/env python
import random, sys
def distribute(parts, value):
total = sum(parts)
min_value = len(parts)
if ((value < min_value) or (value > total)):
return None
cur = [1]*len(parts)
@aniline
aniline / dir615.py
Created November 1, 2016 16:32
Scrape status and stats page off d-link dir-615 hardware ver. T1 Firmware 20.07
#!/usr/bin/env python
#
# DLink DIR-615 HW:T1 FW:20.07 status.
from sys import argv, exit
import urllib as u1
import urllib2 as u2
import bs4
# Router IP
@aniline
aniline / ups.py
Created October 22, 2016 13:24
Collect some stuff form apcupsd.
#!/usr/bin/env python
from subprocess import Popen, PIPE
import urllib2
from time import sleep
p = Popen(['/sbin/apcaccess'], stdout=PIPE, stderr=PIPE)
(o, e) = p.communicate()
status = {}
@aniline
aniline / show_clip.py
Created June 5, 2016 17:12
CLIP desktop notification
#!/usr/bin/env python
import sys, json
from gi.repository import Notify
sys.path.append("paho-mqtt-1.2/src/")
import paho.mqtt.client as mqtt
def _on_connect(client, userdata, rc):
@aniline
aniline / rf24rx.ino
Created October 31, 2015 16:24
ESP8266 + Arduino IDE + nRF24 thingy test prog
#include <SPI.h>
#include <Arduino.h>
#include "nRF24L01.h"
#include "RF24.h"
/* Radio */
RF24 radio(5, 4);
uint64_t address[] = { 0xF2F2F2F20100 };
@aniline
aniline / clip_display_flow.json
Created June 28, 2015 10:25
clip_display_flow.json
[
{
"port": "1883",
"type": "mqtt-broker",
"id": "b30f9506.0d2cf",
"clientid": "",
"broker": "localhost"
},
{
"out": [],
@aniline
aniline / led_display_flow.json
Created June 13, 2015 04:08
LED display flow that I used to test
[
{
"port": "1883",
"type": "mqtt-broker",
"id": "b30f9506.0d2cf",
"clientid": "",
"broker": "localhost"
},
{
"wires": [