Skip to content

Instantly share code, notes, and snippets.

View Ultrabenosaurus's full-sized avatar

Dan Bennett Ultrabenosaurus

  • UK
View GitHub Profile
@Ultrabenosaurus
Ultrabenosaurus / shutdown
Created January 16, 2015 10:47
add scripts to Ubuntu's shutdown process
http://askubuntu.com/questions/416299/execute-command-before-shutdown-reboot
To execute a script at shutdown or reboot:
save your script in /etc/rc6.d
Make it executable: sudo chmod +x K99_script
Notes:
- The script in rc6.d must be with no .sh extension
- The name of your script must begin with K99 to run at the right time.
- The scripts in this directory are executed in alphabetical order.
@Ultrabenosaurus
Ultrabenosaurus / README.md
Created November 28, 2014 16:36
Deferred CSS loader.

Deferred CSS Loader

Based on the example from Google's PageSpeed Insights recommendation on optimising CSS delivery. Modified to be more robust and work in older browsers.

Usage

  1. Include the code in at the bottom of your HTML like Google's example.
  2. Make a server-side list of CSS files to defer.
  3. Convert that list, if it isn't already, to be a series of styles.push( '/path/to/style.css' ); in a single string.

ajax.x - The XMLHttpRequest object (or MS equivalent) used for communication

ajax.serialize(f) f = the form element you wish to be serialized This function serializes all the fields in a form so that they can be passed as a query string in the form 'arg1=val1&arg2=val2'.

ajax.get(url, func) url = the url to query (can contain arguments after a '?') func = the function to call once the response is returned This function uses a GET request to query the specified url and return a response to the specified function.

@Ultrabenosaurus
Ultrabenosaurus / README.md
Created November 28, 2014 16:03
Easily ensure JS namespacing is setup before you access it.

JavaScript Namespacing

This lets you turn this:

window.Foods = window.Foods || {};
Foods.Grains = Foods.Grains || {};
Foods.Grains.Wheat = Foods.Grains.Wheat || {};
@Ultrabenosaurus
Ultrabenosaurus / gitprune.sh
Last active August 29, 2015 14:08
gitprune - delete local branches that aren't on origin
#! /bin/bash
#
# gitprune
#
# @author trustin <https://stackoverflow.com/users/55808/trustin>
# @source http://stackoverflow.com/a/22687460/1734964
# @license unknown, but original code was posted publicly with the intention of being used by others
# @modified Dan Bennett <http://ultrabenosaurus.ninja>
#
@Ultrabenosaurus
Ultrabenosaurus / sif.sublime-snippet
Created October 6, 2014 13:08
quick Sublime snippet for shorthand if statements in PHP and JS
<snippet>
<content><![CDATA[
( ( ${1:if} ) ? ${2:then} : ${3:else} )${4:;}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>sif</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php,source.js</scope>
</snippet>
@Ultrabenosaurus
Ultrabenosaurus / README.md
Last active September 14, 2017 21:50
githash - get the short or full SHA for any commit in your current branch's history

githash

Easily get the short or full SHA for any commit in your current branch's history, useful for reverting and sharing specific code states with others.

Why?

Because typing out git rev-list --max-count=1 --abbrev-commit --skip=# HEAD takes far too much effort.

Installation

@Ultrabenosaurus
Ultrabenosaurus / VagrantMySQL.rb
Last active August 29, 2015 14:06
VagrantMySQL - transfer and run SQL files in a single line, make a queue of SQL files/commands to process at once and in multiple boxes!
#
# VagrantMySQL
#
# A helper for interfacing with MySQL from your Vagrantfile
#
# @author Dan Bennett <http://about.me/d.bennett>
# @package Vagrant\Helpers
# @version 1.0.0
# @license BSD 3-Clause <http://opensource.org/licenses/BSD-3-Clause>
# @todo function DocBlocks!!!!
@Ultrabenosaurus
Ultrabenosaurus / ytsearch.sh
Last active December 20, 2020 23:33
ytsearch - search and launch YouTube videos from bash!
#!/bin/bash
# ytsearch
# original: https://coderwall.com/p/jvuzdg
# created by: Balazs Nadasdi <http://about.me/yitsushi>
# this version: https://gist.github.com/Ultrabenosaurus/8974206b2cba0f1c615a
# edited by: Dan Bennett <http://about.me/d.bennett>
# license: BSD 3-Clause <http://opensource.org/licenses/BSD-3-Clause>
#
# converted to a script for easier redistribution and development
@Ultrabenosaurus
Ultrabenosaurus / clog-php.sublime-snippet
Created September 18, 2014 09:07
basic logging of PHP values in Dev Tools console
<snippet>
<content><![CDATA[
echo "<script type='text/javascript'>if( window.console && console.log ){ var thing = " . json_encode( ${1:thing} ) . "; try{ console.log( JSON.parse(thing) ); }catch(e){ console.log( thing ); } }</script>";
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>clog</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>
<!--