Skip to content

Instantly share code, notes, and snippets.

@sjrdc
sjrdc / schema_validate.cpp
Last active March 3, 2016 07:52
Validite json using libvariant
// copied from https://gist.github.com/lexicalunit since I could not star it
// c++ -I/usr/local/include -L/usr/local/lib -lVariant schema_validate.cpp
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iterator>
cat << EOF > /etc/network/interfaces
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
@sjrdc
sjrdc / rpi audio switch
Last active March 30, 2016 23:13
switch rpi audio output depending on media type played
#!/bin/bash
# requires kodi callbacks plugin - see http://kodi.wiki/view/Add-on:Kodi_Callbacks
# rpi audio switching - https://www.raspberrypi.org/documentation/configuration/audio-config.md
# https://github.com/KenV99/service.xbmc.callbacks2/blob/da7449f3d462cd7fe89a9c343ee3ab5cf3778dc9/default.py
# def playing_type returns [music|movie|episode|stream|liveTV|recordedTV|PVRradio|unknown]
if [ ! $# -eq 1 ]; then
echo "usage: switch_audio mediatype"
exit 1
@sjrdc
sjrdc / ruby_socket.rb
Last active April 19, 2016 19:18
simple socket client example in ruby
require 'socket'
# client socket #
host = piet.net
port = 1234
s = TCPSocket.open(host, port)
while line = s.gets
puts line
@sjrdc
sjrdc / phone.sh
Last active June 14, 2016 14:02
download with wildcard
#!/bin/bash
fileprefix=telefoonlijst
cd /tmp
echo 'mirror --no-empty-dirs -I $fileprefix*' | lftp http://www_rt/telefoon-email-web/
evince "$(ls -1tr $fileprefix* | tail -n 1)" --fullscreen
@sjrdc
sjrdc / list_of_mri_simulators.md
Last active March 1, 2024 06:59
List of MRI simulators
@sjrdc
sjrdc / change_year
Created September 30, 2016 11:25
change year in jpeg date/time metadata
#!/bin/bash
newyear=$1
for j in *.JPG; do
tag=CreateDate
datetime=$(exiftool -$tag $j | sed -e 's|^.*: ||')
year=$(echo $datetime | sed -e 's|:[0-9 :]*||')
newdatetime=${datetime/$year/$newyear}
@sjrdc
sjrdc / Makefile
Created February 7, 2017 22:30 — forked from ddemidov/Makefile
odeint with boost.compute backend
lorenz: lorenz.cpp
g++ -o $@ $^ -std=c++11 -O3 \
-I${HOME}/work/odeint-v2 \
-I${HOME}/work/opencl/compute/include/ \
-lOpenCL -lboost_system -lboost_timer
template <typename R>
class MultiFuncObject
{
std::unordered_map<std::type_index, void(*)()> m_funcs;
public:
template <typename ...A1>
MultiFuncObject<R> operator +=(R(*f)(A1...))
{
@sjrdc
sjrdc / tokenize.cpp
Last active March 1, 2018 14:18
tokenize string
#include <string>
#include <vector>
std::vector<std::string> Tokenize(const std::string& str, const std::string& delimiter)
{
std::vector<std::string> tokens;
if (delimiter.empty())
{
tokens.push_back(str);
}