Skip to content

Instantly share code, notes, and snippets.

View codfish's full-sized avatar

Chris O'Donnell codfish

View GitHub Profile
@codfish
codfish / verify_server_before_deployment.sh
Created February 20, 2015 17:46
Simple bash script to verify targets before a deployment
#!/bin/bash
#
# verify deployment targets
#
declare -A targets
targets=(
["blog.examplehost.com"]='/var/www/path/to/webroot/'
)
@codfish
codfish / mysql_user_grant.sql
Created February 24, 2015 15:57
Create a new mysql user and grant them full priviledges to a specific database only.
-- This will be for ALL hosts, not just localhost, if you want it to only be for
-- localhost, then change 'codfish'@'%' to 'codfish'@'localhost'
CREATE USER 'codfish'@'%' IDENTIFIED BY 'password_here';
GRANT ALL PRIVILEGES ON `database_name`.* TO 'codfish'@'%';
FLUSH PRIVILEGES;
@codfish
codfish / clean_out_pwd.sh
Created February 25, 2015 15:38
Clean out everything in your current working directory, without deleting directory. You can do this with `rm` easily but this way is nicer imo
find . -delete
@codfish
codfish / jquery-animated-scroll.js
Last active August 29, 2015 14:16
Simple jQuery snippet for a "scroll to" animation. Nice replacement for anchor links, rather than abruptly jumping to that spot on the page, this will scroll the page nicely to the desired anchor.
/**
* jQuery animated scroll to
*
* @example
* <a class="animated-scroll" data-target=".elem-selector-scroll-to" data-offset="60">Go to top</a>
*
* @param {data-target} the jquery selector of the dom element you want to scroll to
* @param {data-offset} how far from the top of the window you want the element to be (in pixels). Default is 20px.
*/
$(document).on('click', '.animated-scroll', function(e) {
@codfish
codfish / get_file_counts.sh
Created March 12, 2015 17:22
Get number of files/directories, etc. in a specific directory (recursive).
# Files
find . -type f | wc -l
# Directories
find . -type d | wc -l
# Block special
find . -type b | wc -l
# Character special
@codfish
codfish / flush_memcache.sh
Last active August 29, 2015 14:17
Flush memcache
# display the current memcache process running in order to find the proper port number
ps auxw | grep memcache
# flush memcache. replace <port> with value from above
echo flush_all | nc localhost <port>
@codfish
codfish / xdebug_no_limits.php
Last active August 29, 2015 14:20
Removes limits on xdebug variable output. If xdebug is installed these settings also affect native php functions like `var_dump`
<?php
// @see http://xdebug.org/docs/all_settings
ini_set('xdebug.var_display_max_depth', -1);
ini_set('xdebug.var_display_max_children', -1);
ini_set('xdebug.var_display_max_data', -1);
@codfish
codfish / cast_to_integer.js
Last active August 29, 2015 14:21
JS tip to cast to an Integer, avoiding any NaN pitfalls. "Something to watch out with this approach is for the number to lie within the boundaries of a signed 32-bit integer (or from -2147483648 to 2147483647, inclusively.) Otherwise use your usual Math.floor(). This limitation stems from the fact that we're technically doing a bitwise operation…
// It will always return an integer (never NaN) and will set v to 0 if it was not a number.
// Credit: http://qr.ae/ftLRB
v = ~~v;
@codfish
codfish / filter_false_array_vals.js
Last active August 29, 2015 14:21
Quick way to filter/remove non-truthy (null, empty string, number 0, NaN, boolean false) values from an array in Javascript.
['false', '', false, true, '0', 0, null, NaN, 1, '1'].filter(Boolean);
// => ["false", true, "0", 1, "1"]
@codfish
codfish / define-constants.php
Last active August 29, 2015 14:22
Quick and clean way to define a PHP constant if it doesn't already exist.
<?php
! defined('DB_HOST') && define('DB_HOST', '127.0.0.1');