Skip to content

Instantly share code, notes, and snippets.

Pieter Scheffers PieterScheffers

Block or report user

Report or block PieterScheffers

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
View Javascript - IIFE
(function() {
"use strict";
})();
View 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
View 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();
}
View Javascript - Lib
var lib = (function(window) {
"use strict";
var lib = {};
lib.array = (function() {
var a = {};
a.select = function arraySelect(arr, callback) {
var newArr = [];
View 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++) {
View 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 Mar 13, 2020
node.js pm2 startup script for FreeBSD
View pm2
#!/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:
View 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 Dec 17, 2015
FreeBSD - Find updates for programs in jails
View find_jail_updates.sh
# 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 Jan 26, 2017
FreeBSD - find updates script
View find_updates.sh
#!/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
You can’t perform that action at this time.