Skip to content

Instantly share code, notes, and snippets.

View tjoskar's full-sized avatar

Oskar Karlsson tjoskar

View GitHub Profile
@tjoskar
tjoskar / register.js
Created July 31, 2015 07:19
Register Hapi routers
var path = require('path');
var routePrefix = '_router';
var exports = module.exports;
/**
* Register all sections routes
* @param {exports.Server} server
*/
exports.registerRouts = function(server: hapiServer) {
var sections = ['movies', 'auth', 'series'];
@tjoskar
tjoskar / copy.js
Created June 22, 2015 20:42
Copy files recursive and replace strings
var fs = require('fs');
var path = require('path');
function copyRecursive(src, dest) {
var copyPromises = [];
var copy = function copy(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
@tjoskar
tjoskar / install-all-components.js
Created June 18, 2015 13:52
run "npm install" in all folders under a certain folder
var fs = require('fs');
var path = require('path');
var childProcess = require('child_process');
var dir = './components';
var nodeComand = 'npm install';
var packageFile = 'package.json';
var nodeVersion = process.versions.node.split('.');
if (!(nodeVersion[0] >= 0 && nodeVersion[1] >= 12 && nodeVersion[2] >= 4)) {
@tjoskar
tjoskar / start.py
Created April 26, 2015 08:43
Unrar
import subprocess
import sys
download_base_path = sys.argv[1]
final_destination = sys.argv[2]
"""
Start unrar script in a new process.
This will cause an exit code of 0, even if unrar.py hangs.
"""
@tjoskar
tjoskar / vt-offline.htm
Created April 12, 2015 07:06
Demonstrate bad internet connection
<!DOCTYPE html>
<html>
<head>
<title>VT</title>
<style>
* {
margin: 0;
padding: 0;
}
html, body, #view {
<!DOCTYPE html>
<html>
<head>
<title>Snake</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="snake.js"></script>
<style type="text/css">
.snake_piece {
position:fixed;
left:50%;
import time, os
size = 25
b = [[0 for x in xrange(size)] for x in xrange(size)]
a = [[0 for x in xrange(size)] for x in xrange(size)]
b[10][10] = 1
b[11][11] = 1
<?php
$username = '';
$password = '';
$points = '';
$login_url = 'https://www3.student.liu.se/portal/login';
$redirect = 1;
$redirect_url = '/portal/sv/portal/';
$time = 0;
$login_para = '';
@tjoskar
tjoskar / XBMC_light.py
Created September 14, 2014 12:32
Turn off lamps when using XBMC
import urllib
import xbmc
__HOST__ = '192.168.0.15'
__PORT__ = '8000'
class MyPlayer(xbmc.Player):
__is_playing = False
__url = 'http://' + __HOST__ + ':' + __PORT__
@tjoskar
tjoskar / app.py
Created September 14, 2014 12:07
Tellstick server
import os
import datetime
import pytz
from flask import Flask
from astral import Astral
app = Flask(__name__)
__TELLSTICK_PATH__ = '/usr/bin/tdtool'
__WINDOW_ID__ = ['1', '2', '3']