Skip to content

Instantly share code, notes, and snippets.

View syropian's full-sized avatar
🐝

Collin Henderson syropian

🐝
View GitHub Profile
@syropian
syropian / googleweather.php
Created December 21, 2011 15:12
Grabbing the current conditions and temperature with Google's weather API
<?php
$location = $_GET['q'];
$url = 'http://www.google.com/ig/api?weather='.urlencode($location);
$process = curl_init($url);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($process);
$xml = simplexml_load_string($response);
$temperature = $xml->weather->current_conditions->temp_c['data'].'&deg;C';
$conditions = $xml->weather->current_conditions->condition['data'];
location=`echo Miami Florida | sed -e 's/ /+/'`
curl -s "http://mysite.com/weather.php?q=$location" | sed -e 's/&deg;/°/'
@syropian
syropian / digest.php
Created January 5, 2012 18:21
Function for obtaining a response from a digest-based API in Laravel. The session must contain a username and password, and you must have MCrypt installed for the Crypter class to work.
<?php
class API {
public static function call($url) {
$user = Session::get('username');
$password = Session::get('password');
$process = curl_init($url);
curl_setopt($process, CURLOPT_USERPWD, $user.':'.Crypter::decrypt($password));
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
@syropian
syropian / date.class.php
Created January 18, 2012 19:04
Relative Date Class
<?php
class Date {
public static function torelative($date) {
$diff = strtotime('-1 day') - strtotime($date);
if ($diff>0) {
if ($diff<60)
return $diff . " second" . self::plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<60)
return $diff . " minute" . self::plural($diff) . " ago";
@syropian
syropian / CheckProcess.m
Created May 24, 2012 23:35
Checks if the specififed process is active. Works on all processes (standard and background)
-(BOOL)processIsRunning:(NSString *)aProcess{
NSTask* task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/top"];
NSArray* arguments = [NSArray arrayWithObjects: @"-s", @"1",@"-l",@"3600",@"-stats",@"pid,cpu,time,command", nil];
[task setArguments: arguments];
NSPipe* pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
@syropian
syropian / git-cb.sh
Last active December 18, 2015 14:49
Add this to your bash profile if you want to easily create a remote branch and then checkout a local branch that tracks it.
function git-cb() {
if [ $# -ne 1 ]; then
echo 1>&2 Usage: git-cb branch_name
else
git push origin origin:refs/heads/$1
git fetch origin
git checkout --track -b $1 origin/$1
git pull
fi
}
@syropian
syropian / loopless_sequence
Last active December 20, 2015 02:29
A neat way of creating a sequence in JavaScript, sans loop.
var alphabet = Array.apply(0, Array(26)).map(function(x,y) {
return String.fromCharCode(y + 65);
}).join('');
console.log(alphabet);
//Outputs 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@syropian
syropian / js_obj_helpers.js
Created August 29, 2013 19:53
A few handy JS helper methods for getting the count of a JS object, as well as getting the index of an object by key.
//Helper Methods
function getObjectCount(obj) {
var count = 0;
var key;
for(key in obj) {
if(obj.hasOwnProperty(key)) count++;
}
return count;
}
@syropian
syropian / gist:9218366
Created February 25, 2014 21:35
John Resig's HTML parser, but with support for data-attributes
/*
* HTML Parser By John Resig (ejohn.org)
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
*
* // Use like so:
* HTMLParser(htmlString, {
* start: function(tag, attrs, unary) {},
* end: function(tag) {},
* chars: function(text) {},
@syropian
syropian / gitprompt.sh
Created May 4, 2014 12:45
My bash prompt
PS1='\u:\[\033[0;37m\]\W\e[0m$(__git_ps1 :"\[\033[0;35m\][%s]\e[0m")\$ '