Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers
PieterScheffers / Javascript - IIFE
Last active August 29, 2015 14:20
Javascript - IIFE
(function() {
"use strict";
})();
@PieterScheffers
PieterScheffers / Javascript - Class
Created April 29, 2015 13:38
Javascript - Class
var Person = (function() {
var persons = []; // class variable
function Person(name) {
this.name = name; // normal instance variable
this._password = "secret"; // poor-mans private variable
}
Person.prototype.sayHello = function() { // instance method
var _this = this; // save 'this' for callback functions
@PieterScheffers
PieterScheffers / PHP - Functions
Last active August 29, 2015 14:20
PHP - Functions
// Debug function
// print_r with pre tags
// optionally exit program
function pr($var, $exit=false) {
echo '<pre>';
print_r($var);
echo '</pre>';
if( $exit ) exit();
}
var lib = (function(window) {
"use strict";
var lib = {};
lib.array = (function() {
var a = {};
a.select = function arraySelect(arr, callback) {
var newArr = [];
@PieterScheffers
PieterScheffers / Javascript - Functional functions
Created May 6, 2015 14:20
Javascript - functional functions
function arrayEach(arr, callback) {
for (var i = 0; i < arr.length; i++) {
callback(arr[i], i);
}
}
function arraySelect(arr, callback) {
var newArr = [];
for (var i = 0; i < arr.length; i++) {
@PieterScheffers
PieterScheffers / Javascript - Default value
Created June 16, 2015 08:05
Javascript - Default value
var b,d;
// d = {}; // 5
// d.size = 0; // 5
// d.size = 22; // 22
b = d && d.size || 5;
console.log(b);
@PieterScheffers
PieterScheffers / pm2
Last active March 14, 2023 07:43
node.js pm2 startup script for FreeBSD
#!/bin/sh
# PM2 Startup script
# Source: https://0x0a14.de/pm2-startup-script-for-freebsd/
# Made by: Johannes Tonn
#
# Download this file
# cd /usr/local/etc/rc.d && fetch https://gist.github.com/457769f2090c6b69cd9d
#
# Make the file executable with:
@PieterScheffers
PieterScheffers / Javascript - For Loop
Created June 28, 2015 15:26
Javascript - For Loop
var i, elem, b = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
for(i = 0; elem = b[i],i < b.length; i++) {
console.log(elem);
}
@PieterScheffers
PieterScheffers / find_jail_updates.sh
Last active December 17, 2015 23:36
FreeBSD - Find updates for programs in jails
# portmaster need to be installed in all jails
jls | grep -v JID | tr -s " " | cut -d' ' -f2 | xargs -I {} sh -c 'echo {} && jexec -U root {} portmaster -L | grep New | cut -d: -f2'
# jls # list jails
# grep -v JID # get all lines without JID in it (-v is negation)
# tr -s " " # replace multiple newlines with one
# cut -d' ' -f2 # split string on newlines and select part 2
# xargs -I {} sh -c '' # split string on newlines and spaces into argument list, then use {} as argument placeholder, then execute sh -c command
# sh -c '' # execute sub-shell with commands in string
@PieterScheffers
PieterScheffers / find_updates.sh
Last active January 26, 2017 09:38
FreeBSD - find updates script
#!/usr/bin/env sh
# for finding changes in UPDATING
PKGQUERY=`pkg query %t | sort | tail -n1`
echo "####################################"
echo "# Updating ports collection (Host) #"
echo "####################################"
portsnap fetch update