Skip to content

Instantly share code, notes, and snippets.

View stojg's full-sized avatar

Stig Lindqvist stojg

View GitHub Profile
@stojg
stojg / port-check.sh
Created May 2, 2015 22:55
port-check.sh - small script to check if TCP ports are opened through firewalls etc.
#!/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 / get_links.php
Created November 18, 2010 07:29
Get all links from a website page
@stojg
stojg / sleep.ino
Last active April 4, 2023 14:23
Arduino sleep example
// This is an example how to put an arduino board into deep sleep to save on battery power and
// periodically wake up to run some logic. Ideal for sensor stations like plant moisture sensors.
#include "Arduino.h"
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
// Blink Before sleeping
#define LED_PIN (13)
@stojg
stojg / parse-xml.php
Last active November 18, 2022 21:31
Parsing a huge XML with closure in PHP
<?php
// An example on how to parse massive XML files with PHP by chunking it up to avoid running out of memory
// 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
@stojg
stojg / algo.ts
Created November 4, 2022 00:22
How many of my favourite things should I buy?
function HowManyIsEnough(n: number) : number {
return n + 1
}
@stojg
stojg / server-name-wordlist-mnemonic.txt
Created September 6, 2022 23:12 — forked from bwbaugh/server-name-wordlist-mnemonic.txt
Server name wordlist (mnemonic)
# Original blog post: <https://mnx.io/blog/a-proper-server-naming-scheme/>
# Original word list: <http://web.archive.org/web/20091003023412/http://tothink.com/mnemonic/wordlist.txt>
# Sample usage: `curl <gist> | tail --lines +4 | shuf | head --lines 1`
acrobat
africa
alaska
albert
albino
album
alcohol
@stojg
stojg / ContentAwareImage.php
Created April 23, 2012 05:06
Testing content aware cropping for SilverStripe Idea is that the automatic cropping will crop the most interesting part of the image
<?php
/**
* ContentAwareImage
*
* @author stig
*/
class ContentAwareImage {
protected static $start_time = 0.0;
@stojg
stojg / diskspace.sh
Last active June 8, 2022 22:32
Find sizes of folders in a with a bash oneliner
#!/bin/sh
# Installation: curl -o /usr/bin/diskspace.sh "https://gist.githubusercontent.com/stojg/867224/raw" && chmod +x /usr/bin/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 / remove-tmp-db.php
Created June 13, 2012 00:22
Remove SilverStripe test databases
<?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
@stojg
stojg / postgres_queries_and_commands.sql
Created April 28, 2021 01:28 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'