Skip to content

Instantly share code, notes, and snippets.

View adamdehaven's full-sized avatar

Adam DeHaven adamdehaven

View GitHub Profile
@adamdehaven
adamdehaven / ShortTail-Bookmarklet
Created February 12, 2014 16:05
ShortTail Bookmarklet
javascript:(function()%7Bjavascript%3Awindow.location.href%3D'ShortTail%3A%2F%2F'%2Bwindow.location.href%7D)();
@adamdehaven
adamdehaven / calculate-dates-obj-c
Created March 13, 2014 19:48
Calculate Dates in Objective-C
- (void) calculateDates {
NSDate *todayDate = [[NSDate alloc] init];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *tomorrowOffset = [[NSDateComponents alloc] init];
[tomorrowOffset setDay:1];
NSDateComponents *yesterdayOffset = [[NSDateComponents alloc] init];
[yesterdayOffset setDay:-1];
NSDate *tomorrowDate = [gregorian dateByAddingComponents:tomorrowOffset toDate:todayDate options:0];
NSDate *yesterdayDate = [gregorian dateByAddingComponents:yesterdayOffset toDate:todayDate options:0];
@adamdehaven
adamdehaven / Blur Current View
Last active August 29, 2015 14:01
Blur current view
#import "UIImage+ImageEffects.h"
// Blur view while sidebar is open
UIGraphicsBeginImageContext(self.tableView.contentSize);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, 0, 0);
[self.view.layer renderInContext:c];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
viewImage = [viewImage applyBlurWithRadius:3.5 tintColor:nil saturationDeltaFactor:1.4 maskImage:nil];
UIGraphicsEndImageContext();
@adamdehaven
adamdehaven / human-time-diff.php
Last active September 28, 2015 17:13
Wordpress function to insert post or comment timestamp as relative (i.e. 2 weeks ago), or as date, depending on $duration (Default 60 days)
<?php
// Show relative time if more recent than 60 days for post or comment
function adamdehaven_human_time_diff( $type = 'post', $duration = 60 ) {
if($type == 'comment') {
$post_time = get_comment_time('U');
} else {
$post_time = get_the_time('U');
}
$human_time = '';
@adamdehaven
adamdehaven / http-status-code.php
Last active September 28, 2015 17:13
Easily return HTTP status messages on success and failure
<?php
function getStatusCodeMessage($status)
{
// these could be stored in a .ini file and loaded
// via parse_ini_file()... however, this will suffice
// for an example
$codes = Array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
/* =============================================================================
CSS Declarations
========================================================================== */
/* ==|== The Standard Way =================================================== */
.foo::before {
/* ...css rules... */
}
@adamdehaven
adamdehaven / network-connectivity.sh
Created April 27, 2016 19:45
Bash/Terminal check if a URL can be reached via cURL
#!/bin/bash
case "$(curl -s --max-time 2 -I $1 | sed 's/^[^ ]* *\([0-9]\).*/\1/; 1q')" in [23]) echo "HTTP connectivity is up";; 5) echo "The web proxy will not let us through";; *) echo "The network is down or very slow";; esac
### Run
# $ bash network-connectivity.sh http://google.com/
### Result
# $ HTTP connectivity OK
@adamdehaven
adamdehaven / http-status.sh
Last active April 27, 2016 19:46
Bash/Terminal to return the HTTP status code of a URL via cURL. Includes following redirects to final URL
#!/bin/bash
status=$(curl $1 -s -L -I -o /dev/null -w '%{http_code}')
echo $status
### Run
# $ bash http-status.sh http://google.com/
@adamdehaven
adamdehaven / .gitconfig
Created May 17, 2016 16:06 — forked from rab/.gitconfig
A good starting point for ~/.gitconfig
# -*- Conf -*-
[color]
branch = auto
diff = auto
status = auto
showbranch = auto
ui = true
# color.branch
# A boolean to enable/disable color in the output of git-branch(1). May be set to always, false (or
@adamdehaven
adamdehaven / cookies.js
Created February 27, 2017 14:02
Create, read, and destroy cookies with javascript
/**
* Cookie functions
*/
function createCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}