Skip to content

Instantly share code, notes, and snippets.

View adamgreig's full-sized avatar

Adam Greig adamgreig

View GitHub Profile
@adamgreig
adamgreig / make_farnell_bom.py
Created July 29, 2014 16:57
Turn a CSV number,qty of Farnell parts into a txt of name,number,url,qty,unit cost,total cost
import requests
from lxml import html
import json
parts = {}
with open("farnell_bom_condensed.txt") as f:
for line in f:
number, qty = line.split(", ")
qty = int(qty)
url = "http://uk.farnell.com/_/_/dp/{}".format(number)
@adamgreig
adamgreig / main.c
Created August 30, 2013 22:37
BladeRF testing
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <math.h>
#include "libbladeRF.h"
int main(int argc, char* argv[]) {
struct bladerf *dev;
int status;
@adamgreig
adamgreig / gist:6233882
Created August 14, 2013 18:18
TOPT Codes
import time
import hmac
import struct
import base64
import hashlib
def code(secret):
key = base64.b32decode(secret)
message = struct.pack(">Q", int(time.time()) / 30)
h = hmac.new(key, message, hashlib.sha1).digest()
@adamgreig
adamgreig / lmt2.c
Last active December 20, 2015 22:08
Calculate R and N register values for the LMT2 integer-N PLL. Skips a lot of potential solutions so will only be accurate to within a couple of kHz, but finds results very quickly, even on 8 bit embedded platforms. Some more details: http://nbviewer.ipython.org/urls/randomskk.net/u/lmt2.ipynb
/*
* lmt2.c - Calculate R and N register values for an LMT2 PLL.
* Written in 2013 by Adam Greig <adam@adamgreig.com>
*
* To the extent possible under law, the author has dedicated all copyright
* and related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*
* For details, see http://creativecommons.org/publicdomain/zero/1.0/
*
@adamgreig
adamgreig / iib_countdown.c
Last active December 17, 2015 14:19
Simple "hours remaining" countdown clock for Pebble. Counts down until the deadline for my Masters project!
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x8B, 0xA6, 0x5F, 0x1D, 0xB1, 0x08, 0x44, 0xAA, 0xA8, 0x17, 0x17, 0xFE, 0xCD, 0x3A, 0x89, 0xDA }
PBL_APP_INFO(MY_UUID,
"IIB Countdown", "Adam Greig",
1, 0, /* App version */
DEFAULT_MENU_ICON,
@adamgreig
adamgreig / gist:5383809
Last active December 16, 2015 05:19
Powerline prompts for fish
set fish_greeting
function activate
set -x VIRTUAL_ENV_DISABLE_PROMPT '1'
. venv/bin/activate.fish
end
function fish_prompt
if [ $USER = "root" ]
set_color -b RED WHITE
@adamgreig
adamgreig / gist:5383561
Last active December 16, 2015 05:19
my fish.config
set fish_greeting
function activate
set -x VIRTUAL_ENV_DISABLE_PROMPT '1'
. venv/bin/activate.fish
end
function fish_prompt
if [ $USER = "root" ]
set_color -b RED WHITE
@adamgreig
adamgreig / email_away_highlights.py
Created December 14, 2012 02:20
Weechat script to send an email when a new highlight or privmsg is received while away. NB only checks away status of the first server.
# -*- coding: utf-8 -*-
# Copyright 2012 Adam Greig <adam@adamgreig.com>
#
# email_away_highlights.py
# Email highlights received while away.
SCRIPT_NAME = "email_away_highlights"
SCRIPT_AUTHOR = "Adam Greig <adam@adamgreig.com>"
SCRIPT_VERSION = "1.0"
SCRIPT_LICENSE = "GPL3"
import couchdbkit
import datetime
import hashlib
import base64
import time
s = couchdbkit.Server("http://localhost:5984")
NUMDOCS = 1000000
import logging
import couchdbkit
db = couchdbkit.Server("http://habitat.habhub.org/")['habitat']
#db = couchdbkit.Server("http://localhost:5984/")['test_fieldnames']
mapping = {
'Sats': ('satellites', None),
'temp_int': ('temperature_internal', None),
'main_battery_volts': ('battery', None),
'pressure_hpa': ('pressure', 100.0),