Skip to content

Instantly share code, notes, and snippets.

View fredrike's full-sized avatar

Fredrik Erlandsson fredrike

View GitHub Profile
update post_play set likes_count=(select count(*) from likedby as ls where ls.page_id=post_play.page_id AND ls.post_id=post_play.id AND ls.comment_id=0) WHERE likes_count IS NULL limit 1000000;
update post_play set comments_count=(select count(*) from comment co where co.page_id=post.page_id AND co.post_id=post.id) WHERE comments_count IS NULL limit 1000000;
#!/usr/bin/env bash
# ================================================================================
# A git-diftool utility for a TeX file using `latexdiff`.
#
#
# Usage
# -----
# git latexdiff [<commit>]
# git latexdiff --cached [<commit>]
#
@fredrike
fredrike / emon.sh
Last active August 29, 2015 14:08
Upload script for emoncms.org with data from openenergy monitor
#!/bin/sh
APIKEY="YOUR KEY"
trap '' 1 2 9 15 SIGSTOP
stty -F /dev/usb/acm/0 9600 -hupcl
while true; do
if [ -r /dev/usb/acm/0 ]; then
/*
* Nexa Receiver
* Controls 4 relays connected to Aurduino I/O pins.
* Transmitter codes are hard-coded as a fixed number in the Sketch.
* src: http://www.telldus.com/forum/viewtopic.php?f=12&t=4072
*
* The code has been validated to work with the following NEXA transmitters:
*
* WBT 912 2ch sender
* WT2 PRO 2ch Wall sender
@fredrike
fredrike / mssql.php
Last active August 29, 2015 14:19
Test connection to SQL Server @ BTH
<html>
<title>BTH Database Test</title>
<pre>
<?php
DEFINE("_SQL_SERVER_", "194.47.129.139");
DEFINE("_SQL_USER_", "");
DEFINE("_SQL_PASSWORD_", "");
DEFINE("_SQL_DATABASE_", _SQL_USER_);
@fredrike
fredrike / telldus.py
Last active August 29, 2015 14:21
telldus.py
import oauth2 as oauth
import json, time, requests, datetime
import re, string
XIVELY_API_KEY = ""
XIVELY_FEED_ID = ""
TELLDUS_PUB_KEY = ""
TELLDUS_PRIV_KEY = ""
TELLDUS_TOKEN = ""
TELLDUS_SECRET = ""

Install raspbian wheezy packages:

sudo apt-get install git python3-pip redis-server rabbitmq-server libxml2-dev python3-lxml python3-crypto yum

Install mongodb (not includes in default repo) from https://github.com/tjanson/mongodb-armhf-deb:

wget https://github.com/tjanson/mongodb-armhf-deb/releases/download/v2.1.1-1/mongodb_2.1.1_armhf.deb
sudo apt-get install libboost1.49-dev libicu48 libboost-dev
sudo dpkg -i mongodb_2.1.1_armhf.deb

sudo /etc/init.d/mongodb start

"""
Change the constants below.
"""
fileName = "INSERT FILENAME"
API = "INSERT API-WRITE-KEY"
nodeID = 13
urlString = "http://emoncms.org/input/bulk.json?time=%d&apikey=%s&data=["
import pandas as pd
import tarfile
import os
from glob import glob
import sys
with tarfile.open(sys.argv[1]) as tar:
for f in tar:
name = f.name[:-5]
if os.path.isfile(name + "#001.json"):
index = len(glob(name + "*")) + 1