Skip to content

Instantly share code, notes, and snippets.

Stig Lindqvist stojg

Block or report user

Report or block stojg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stojg
stojg / sleep.ino
Last active May 6, 2019
Arduino sleep example
View sleep.ino
#include "Arduino.h"
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
// Blink Before sleeping
#define LED_PIN (13)
// This variable is made volatile because it is changed inside
// an interrupt function
@stojg
stojg / parse-xml.php
Last active Feb 11, 2019
Parsing a huge XML with closure in PHP
View parse-xml.php
<?php
// Open the XML
$handle = fopen('file.xml', 'r');
// Get the nodestring incrementally from the xml file by defining a callback
// In this case using a anon function.
nodeStringFromXMLFile($handle, '<item>', '</item>', function($nodeText){
// Transform the XMLString into an array and
print_r(getArrayFromXMLString($nodeText));
@stojg
stojg / diskspace.sh
Last active Sep 12, 2018
Find sizes of folders in a with a bash oneliner
View diskspace.sh
#!/bin/sh
# Installation: curl -o diskspace.sh "https://gist.githubusercontent.com/stojg/867224/raw/diskspace.sh" && chmod +x diskspace.sh
du -xsk ./* | sort -n | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t",int(x*10)/10,pref[y],$0); } { for (i=2; i<=NF; i++) printf "%s ", $i; printf "\n"; } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'
@stojg
stojg / port-check.sh
Created May 2, 2015
port-check.sh - small script to check if TCP ports are opened through firewalls etc.
View port-check.sh
#!/bin/bash
function checkport {
if nc -zv -w30 $1 $2 <<< '' &> /dev/null
then
echo "[+] Port $1/$2 is open"
else
echo "[-] Port $1/$2 is closed"
fi
}
@stojg
stojg / consul
Created Dec 1, 2014
consul service init script for debian
View consul
#!/bin/sh
### BEGIN INIT INFO
# Provides: consul
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Consul service discovery framework
# Description: Healthchecks local services and registers
# them in a central consul database.
View Flowdock.php
<?php
/**
* Send an message to a Flowdock "flow".
*
* # Initialization:
* <code>
* $fd = new Flowdock();
* $fd->setToken('asdadsads');
* </code>
*
@stojg
stojg / Flowdock.php
Created Nov 5, 2013
Sending a message via php and curl to a flowdock "flow"
View Flowdock.php
<?php
/**
* Send an message to a Flowdock "flow".
*
* # Initialization:
* <code>
* $fd = new Flowdock();
* $fd->setToken('asdadsads');
* </code>
*
@stojg
stojg / slowpoke.go
Created Dec 16, 2017
go program to run after a slow process, which sends you a text so that you know when it's finished
View slowpoke.go
// This golang program is a remix/parody of https://gist.github.com/mrmorphic/7cb86c7b1a5e3da9d8664d6e8a1e3518
// that notifies the user that notifies a user after a slow process have finished, but instead of using the computers
// speech synthesiser or notification system, sends you a text instead. This means that you can leave the safe confines
// of your desk while scavenging office supplies, stalk colleagues or have a quiet smoko. I.e. it's the 2020 version of
// https://xkcd.com/303/. Ideal for those dependency fetching / compiling steps.
//
// To make this work you need to at least setup a `https://www.twilio.com` trial account and define a couple ENV
// variables:
//
// # Get this from your twilio account
@stojg
stojg / Cache_Stamped_example.php
Created Jul 20, 2014
Cache Stampede example
View Cache_Stamped_example.php
<?php
/**
* Cache stampede protection examples
*/
class cache
{
/**
* @var array
@stojg
stojg / remove-tmp-db.php
Created Jun 13, 2012
Remove SilverStripe test databases
View remove-tmp-db.php
<?php
/**
* This script will drop all the databases that contains this string 'tmpdb'.
* Those databases are likely to be left over from a SilverStripe test run
* Usage: Make sure you change the db connection string below and run the
* script like:
* php remove-tmp-db.php
*/
// Change this to your db connection
You can’t perform that action at this time.