Skip to content

Instantly share code, notes, and snippets.

View message.json
{
"0702": {
"03": {
"01": "000001",
"05": "43",
"04": "9B",
"02": "0003E8",
"07": "22000134454XX", // MPAN
"08": "19P69009XX", // Meter Serial Number
"03": "43",
@sammachin
sammachin / main.py
Created Jul 27, 2020
Octopus Rating
View main.py
import pickle
import requests
from datetime import datetime, timedelta, time
import csv
# Octopus Fixed Tarrif Rates (check for your region)
go_day = 14.5
go_night = 5
e7_day = 18.04
e7_night = 9.38
@sammachin
sammachin / slack-move.py
Last active Jan 29, 2019
some functions for getting slack users in a channel and adding them to a new channel
View slack-move.py
from slackclient import SlackClient
TOKEN = "xoxp-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
sc = SlackClient(TOKEN)
#get a dict of channel names to channel IDs
def get_channels():
channels = {}
data = sc.api_call("conversations.list", types='public_channel', exclude_archived=True, limit=1000)
@sammachin
sammachin / setup.sh
Last active Dec 21, 2018
PI Starter
View setup.sh
#! /bin/bash
CARDPATH=$1
#Enable SSH
touch $CARDPATH/ssh
#Configure WiFi
cp wpa_supplicant.conf $CARDPATH/wpa_supplicant.conf
@sammachin
sammachin / howto.md
Last active Nov 2, 2018
Making API Requets using JWT and HTTPie
View howto.md

HTTPie is AWESOME! if you're still using cURL do yourself a favor and get this https://httpie.org/

Here's a quick guide to make requests to the nexmo API that need to be authenticated with JWT and have a JSON request body.

You will need:

  • The Nexmo CLI installed
  • The private key for your application stored in a local file named private.key
  • The applicaiton ID of your applicaiton
  • The payload of the request in a file called request.json (see example)
View ncco.json
[
{
"endpoint": [
{
"uri": "wss://<your-server-address>/socket",
"type": "websocket",
"headers": {
"app": "demo"
},
"content-type": "audio/L16;rate=16000"
@sammachin
sammachin / playlist_titles.py
Last active Sep 14, 2018
Short script to print all the titles in a YouTube Playlist
View playlist_titles.py
import requests
playlist = "XXXXXXX" #Playlist ID from URL eg https://www.youtube.com/playlist?list=PL1Hr6VkuONaE4XM52ThiV-s3vXAUT0JCR
key = "XXXXXXXX" # Your YouTube API Key from https://console.developers.google.com/apis/credentials
params = {"part" : "snippet", "maxResults" : 50, "playlistId": playlist, "key" : key}
url = "https://www.googleapis.com/youtube/v3/playlistItems"
items = []
r = requests.get(url, params=params)
rdata=r.json()
@sammachin
sammachin / install.sh
Created Apr 30, 2018
Node building blocks webhook prereqs
View install.sh
npm install express
npm install body-parser
@sammachin
sammachin / install.sh
Created Apr 30, 2018
Python Nexmo Client pre-reqs
View install.sh
pip install nexmo
@sammachin
sammachin / install.sh
Created Apr 30, 2018
python webhook pre-requisites
View install.sh
pip install ‘flask>=1.0’