Skip to content

Instantly share code, notes, and snippets.

View aweijnitz's full-sized avatar

Anders Weijnitz aweijnitz

View GitHub Profile
@aweijnitz
aweijnitz / DateAritmethics
Created March 25, 2014 20:33
Illustration of basic date arithmetics in Java.
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class DateAritmethics {
public static void main(String[] args) {
@aweijnitz
aweijnitz / Basic Template Engine
Last active August 29, 2015 14:04
Three-line Template Engine in Javascript for quick substitution of object properties into a string
/**
* A mini "template engine".
* Arguments:
* template - A string of looking like "Something {{variableName}} and {{nested.object.data}}"
* data - A Javascript object with properties to substitute into the template
*
* Returns:
* A string with the variables substituted with the corresponding properties from the data
*/
var applyTemplate = function(template, data) {
@aweijnitz
aweijnitz / setupSecurity.sh
Last active August 29, 2015 14:14
Basic firewall and connection autobanning on Debian
#!/bin/bash
#
# ____ Install Uncomplicated Firewall (frontend to iptables)
#
sudo apt-get install -y ufw
# Be paranoid
sudo ufw disable
@aweijnitz
aweijnitz / installIOJS.sh
Created January 30, 2015 21:33
script to install io.js
#!/bin/sh
su -
mkdir ./downloads
cd downloads
rm -rf /uss/lib/iojs*
rm /usr/bin/iojs
rm /usr/bin/node
rm /usr/bin/npm
@aweijnitz
aweijnitz / listBannedIPs.sh
Created January 30, 2015 21:34
list banned IP addresses in iptables
sudo iptables -L -n
@aweijnitz
aweijnitz / NFT_Setup
Created May 3, 2015 19:04
Hydro Balicony 2015 Quick Summary
# Quick Summary Of Balcony Hydroponic Garden
## Rig
- 2*120cm PVC pipe + bends and fittings
- 60l capcaity tank with about 25l nutrient water.
- 4*2 holes, 7 chilis, 1 tomato
- Type: [Nutrient Film Technique](http://en.wikipedia.org/wiki/Nutrient_film_technique)
- Pump schedule: 4 runs per hour, 20 seconds per run (pump a bit too powerful)
[The rig](http://i.imgur.com/T3ySmOS.jpg)
@aweijnitz
aweijnitz / remoteBackup.sh
Created May 21, 2015 13:00
rsync based remote backup
#!/bin/bash
sudo rsync -avz --delete --one-file-system / /boot backupuser@80.86.92.244:/home/hydrobackup/backups
@aweijnitz
aweijnitz / copySubmissions.php
Last active December 29, 2015 18:39
PHP script to copy ukulele advent calendar submissions using the day of month as base file name (i.e. 1.htm, 1.mp3, 1.jpg on Dec 1st and so on)
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
// Change these to actual directory paths (including trailing slash '/')
$SOURCE_DIR = '/Users/anders/tmp/from/';
$DESTINATION_DIR = '/Users/anders/tmp/to/';
@aweijnitz
aweijnitz / RF Link 433Mhz receiver
Last active January 4, 2016 11:14
RF Link 433MHz debug setup for Arduino
@aweijnitz
aweijnitz / sqlite3_example.js
Last active February 26, 2017 19:12
Example how to use SQLite with Node.js
/**
* Small refresher on how to use sqlite3 embedded in node.js
*
* LINKS:
* - Package: https://www.npmjs.com/package/sqlite3 (NOTE: Includes correct platform binary of sqlite3. No extra install required.)
* - API: https://github.com/mapbox/node-sqlite3/wiki/API
*/
var sqlite3 = require('sqlite3').verbose();
// var db = new sqlite3.Database('./dbfiles/testdb');