Skip to content

Instantly share code, notes, and snippets.

@olimortimer
olimortimer / gist:9c6c3cf8d1364f4fe9d2
Created September 19, 2014 15:08
Shell: Ping with timestamp
# Ping with timestamp
ping google.com | while read pong; do echo "$(date): $pong"; done
# Ping to file
ping google.com >> ping.txt
# Ping with timestamp to file
ping google.com | while read pong; do echo "$(date): $pong"; done >> ping.txt
@olimortimer
olimortimer / gist:2eb5b14ecda5734e76b4
Created September 8, 2014 10:12
JS: Serialize disabled form elements
// Serialize all our form elements with a value, including disabled
$.fn.serializeAllForm = function () {
return $.param(
$.makeArray(
$(':input[value!=""]', this)
)
);
}
@olimortimer
olimortimer / gist:aade89e7e263f22069f5
Last active August 29, 2015 14:04
PHP: Catch script failure
<?php
// Multiple ways of registering a function for execution on shutdown
// Class method
public function __construct() {
register_shutdown_function(array($this, 'scriptFailure'));
}
// Non-class method
register_shutdown_function('scriptFailure');
# View live logs
tail -f FILE
# View live logs which only matches our IP
tail -f FILE | grep --line-buffered IP_ADDRESS
@olimortimer
olimortimer / gist:5938473652dc4c955eb2
Created May 27, 2014 15:10
Shell: Trim lines from file
# Save all lines after line number X (1000000), from one file into another
tail -n +1000001 error_log > error_log_trimmed
@olimortimer
olimortimer / gist:9394985
Last active August 29, 2015 13:57
JS: Disable Javascript Console
(function() {
try {
var $_console$$ = console;
Object.defineProperty(window, "console", {
get: function() {
if ($_console$$._commandLineAPI)
throw "Sorry, for security reasons, the script console is deactivated";
return $_console$$
},
set: function($val$$) {
@olimortimer
olimortimer / gist:8801155
Created February 4, 2014 10:20
PHP: Replacement http_build_query
<?php
/**
* Recursive function to work through the data
*
* http_build_query in php 5 will screw up array serialisation by encoding the square brackets
* and make it incompatible for passing to an URL's GET segment or sending through post data manually
*
* Thanks to Marco K. (link below), A version intended for php < 5 actually encodes the data correctly
*
@olimortimer
olimortimer / gist:8687279
Last active January 4, 2016 22:19
PHP > JS Functions
<?php
$data = array();
foreach ($products as $product) {
$data[$product->make][$product->variant.' - '.$product->material][] = $product;
}
@olimortimer
olimortimer / post-checkout
Created December 13, 2013 15:56
Git Hooks
#!/bin/bash
# Post checkout runs during branch switching
# Used to copy over a branch specific config.js file
branch="$(git rev-parse --abbrev-ref HEAD)"
config='mobile/assets/js/config.js'
# Check if our file exists
@olimortimer
olimortimer / gist:7353538
Created November 7, 2013 12:02
JS: Delay
var delay = (function() {
var timer = 0;
return function(callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
// Set a delay before doing something else - ie, wait until they've stopped typing
delay(function() {