Skip to content

Instantly share code, notes, and snippets.

@thom-nic
thom-nic / wpa_supplicant-dd.txt
Created June 7, 2012 17:18
wpa_supplicant output
root@raspbian:~# wpa_supplicant -i wlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf -dd
wpa_supplicant v1.0
random: Trying to read entropy from /dev/random
Initializing interface 'wlan0' conf '/etc/wpa_supplicant/wpa_supplicant.conf' driver 'default' ctrl_interface 'N/A' bridge 'N/A'
Configuration file '/etc/wpa_supplicant/wpa_supplicant.conf' -> '/etc/wpa_supplicant/wpa_supplicant.conf'
Reading configuration file '/etc/wpa_supplicant/wpa_supplicant.conf'
ctrl_interface='/var/run/wpa_supplicant'
ctrl_interface_group='0'
ap_scan=2
Line: 16 - start of a new network block
@thom-nic
thom-nic / dmesg.out
Created June 12, 2012 16:53
new dmesg and wpa_supplicant output for raspbian
6.611593] 0x30 0x14 0x01 0x00 0x00 0x0f 0xac 0x04
[ 476.622731] 0x01 0x00 0x00 0x0f 0xac 0x04 0x01 0x00
[ 476.634192] 0x00 0x0f 0xac 0x02 0x00 0x00 0xd4 0xcc
[ 476.645687] =>rtw_wx_set_essid
[ 476.654897] ssid=EW, len=2
[ 476.663757] Set SSID under fw_state=0x00000008
[ 476.674480] <=rtw_wx_set_essid, ret 0
[ 482.689276] wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM
[ 482.700379] set_mode = IW_MODE_INFRA
[ 482.710917]
@thom-nic
thom-nic / example.py
Created March 5, 2013 19:50
Handler for authenticating HTTPS connections with urllib2. (Python 2.x) Note that the 'ciphers' option in ssl.wrap_socket is python 2.7 only.
import logging, urllib2
import https
client_cert_key = None # file path
client_cert_pem = None #file path
ca_certs = None # file path
handlers = []
handlers.append( HTTPSClientAuthHandler(
@thom-nic
thom-nic / enoc_open_sql.rb
Created March 29, 2013 13:34
Script to load EnerNOC Open data (see http://open.enernoc.com/data) into a relational database. Note that this resulted in a ~500 MB sqlite file for all 100 sites in the 2012 dataset. Once the data is loaded, you can make standard relational queries over the data such as: select r.* from readings r join sites s on r.site_id = s.site_id where s.i…
require 'sqlite3'
require 'csv'
module ENOC
##
# Functions to load EnerNOC Open Data (http://open.enernoc.com/data)
# into a sqlite database for relational access. This sould be easy
# to migrate to Postgres or MariaDB if you want a 'real' database.
#
module Sql
@thom-nic
thom-nic / cx_oracle_instructions.md
Created July 16, 2013 19:14
Installing CX Oracle for Python & Mac OS X. Instructions exist around the web, but they seem to be piecemeal and incomplete.
@thom-nic
thom-nic / Rakefile
Created August 20, 2013 20:43
Octopress rake tasks for deploying to S3 and pinging sitemaps
# Add this w/ your other imports:
begin
require 'aws/s3'
require 'yaml'
rescue
puts "No S3 upload support!"
end
# and in your config section...
s3_config_file = "amazon_s3.yml" # location of file with S3 access key, private key, bucket name
@thom-nic
thom-nic / socket_timeout_example.py
Created September 9, 2013 21:42
On a slow connection, you might want the send timeout to be different from receive timeout
import logging
import socket, ssl
host = 'www.google.com'
use_ssl = False
port = 443 if use_ssl else 80
ca_certs = None # or path/to/ca_file.pem
sock = socket.socket(Socket.AF_INET, Socket.SOCK_STREAM)
# self.socket.settimeout(1)
@thom-nic
thom-nic / http_example.py
Last active July 21, 2016 23:46
Worried about weak SSL/TLS versions when doing HTTPS requests in Python? All current releases of Python (<= 3.3) do *not* support the latest TLS version 1.2. This is a TLS 1.2 adapter for urllib2/ httplib. Requires a fork of PyOpenSSL found here: https://github.com/enernoc/pyopenssl
'''
Simple urllib example to demonstrate how to use the `tls12_http` module.
'''
import urllib2
import json
from tls12_http import TLS1_2AuthHandler
client_key = None #'client_key.pem'
@thom-nic
thom-nic / _screen
Created October 10, 2013 19:08
zsh autocomplete for screen + usbserial. Drop this in ~/.oh-my-zsh/plugins/screen/
#compdef screen
_arguments -s -S ":tty:_files -g /dev/tty*" \
":baud:(9600 115200)" && return 0
return 1
@thom-nic
thom-nic / ImageDownloader.java
Last active December 26, 2015 05:19
Enhanced Android image downloader with persistent local cache based on a hash of the image URL. Cached files are automatically expired based on last access time. First revision shows the original source from http://goo.gl/zUxFD6 so it's clear what I've added.
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software