Skip to content

Instantly share code, notes, and snippets.

View badcrocodile's full-sized avatar

Jason badcrocodile

  • The Motley Fool
  • Austin, Texas
View GitHub Profile
@badcrocodile
badcrocodile / post-merge
Last active June 22, 2016 18:02 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# Forked by badcrocodile to check for changed files in a specified directory
# git hook to run a command after `git pull` if any files in a specified directory have been changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
@badcrocodile
badcrocodile / 0_reuse_code.js
Created February 4, 2016 18:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@badcrocodile
badcrocodile / gradient-filled-progress-bar.php
Created December 22, 2015 19:28
Uses GD Library to create a progress bar. The bar itself is filled with a gradient. Nice!
<?php
/**
* Available GET parameters:
*
* == COLORS ==
* bg_r - Red component of bar background color
* bg_g - Green component of bar background color
* bg_b - Blue component of bar background color
* from_r - Red component of gradient start
@badcrocodile
badcrocodile / select-columns.css
Created December 10, 2015 18:06
:nth-child CSS Selectors for 3-Column Galleries
/* first column */
.one-third:nth-child(3n-2){
margin-left: 0;
}
/* middle column */
.one-third:nth-child(3n+2) {
padding:5px
}
@badcrocodile
badcrocodile / getpriceimage.php
Last active November 26, 2015 03:12
Create images on the fly
<?php
header("Content-type: image/png");
$image = imagecreatefrompng("bubble3.png");
$price = (int)$_GET['price'];
$font = 'arialbd.ttf';
$fontsize = 8;
$color = imagecolorallocate($image,255,255,255);
$px_top = 16;
switch(true) {
case ($price > 0 && $price <= 5000): // $price returns 0 if string is passed
@badcrocodile
badcrocodile / slack_notification.php
Created October 29, 2015 14:27 — forked from alexstone/slack_notification.php
Fire a Slack Notification via CURL
<?php
// (string) $message - message to be passed to Slack
// (string) $room - room in which to write the message, too
// (string) $icon - You can set up custom emoji icons to use with each message
public static function slack($message, $room = "engineering", $icon = ":longbox:") {
$room = ($room) ? $room : "engineering";
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"text" => $message,
@badcrocodile
badcrocodile / Gruntfile.js
Created September 7, 2015 02:02
My working gruntfile.
module.exports = function(grunt) {
require('time-grunt')(grunt);
require('load-grunt-config')(grunt, {
jitGrunt: true
});
grunt.initConfig({
less: {
@badcrocodile
badcrocodile / detectAdsLoaded.js
Created August 20, 2015 18:41
Detect when Google Ads API is loaded and when ads are ready and loaded in the DOM
window.googletag = window.googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(detectAdLoad);
function detectAdLoad() {
/**
* NOTE: This function depends on the ad slot ID (var targetSlot). If this changes, this function will break
*
* Patched together using documentation at https://developers.google.com/doubleclick-gpt/reference
@badcrocodile
badcrocodile / betterTimeout.js
Created August 19, 2015 01:34
Alternative to setTimeout()
function interval(func, wait, times){
var interv = function(w, t){
return function(){
if(typeof t === "undefined" || t-- > 0){
setTimeout(interv, w);
try{
func.call(null);
}
catch(e){
t = 0;
@badcrocodile
badcrocodile / count_queries.php
Last active August 29, 2015 14:23
Display the Number of SQL Queries on Your blog. For dump_all_queries add ?debug=sql to any WP URL
<?php if (is_user_logged_in()) { ?>
<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.
<?php } ?>