Skip to content

Instantly share code, notes, and snippets.

View danielcbaldwin's full-sized avatar

Daniel Baldwin danielcbaldwin

View GitHub Profile
/**
* Sample jQuery Plugin
*/
(function($) {
function Sample() {};
$.extend(Sample.prototype, {
settings: {
base_url: ''
},
/**
* Sample jQuery Plugin
*/
(function($) {
function Sample() {};
$.extend(Sample.prototype, {
settings: {
base_url: ''
},
<?php phpinfo(); ?>
@danielcbaldwin
danielcbaldwin / gist:880041
Created March 21, 2011 19:31
A handy function for PHP that checks if a string is actually something that has been serialized
<?php
/**
* Checks if data is serialized
* @param mixed $data
*/
public function is_serialized($data) {
if (!is_string( $data)) {
return false;
}
@danielcbaldwin
danielcbaldwin / is_mobile.php
Created March 22, 2011 15:27
Piece of code to determine if the client is on a mobile device.
<?php
function is_mobile() {
$mobile_browser = 0;
if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
$mobile_browser++;
}
if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
$mobile_browser++;
<img src="http://lorempixum.com/400/200" alt="" />
@danielcbaldwin
danielcbaldwin / serialize_check.php
Created July 31, 2011 23:33
Function to check if a string is actually serialized data.
/**
* Checks if data is serialized
* @param mixed $data
*/
public function is_serialized($data) {
if (!is_string( $data)) {
return false;
}
$data = trim($data);
#!/usr/bin/env sh
warn() {
echo "$1" >&2
}
die() {
warn "$1"
exit 1
}
@danielcbaldwin
danielcbaldwin / git_info_addition_to_bash_prompt.sh
Created March 29, 2012 19:41
Git info addition to Bash prompt
# setup the prompt with git branch
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\u:\w$(__git_ps1 "[\[\e[0;32m\]%s\[\e[0m\]\[\e[0;33m\]$(parse_git_dirty)\[\e[0m\]]")$ '
export PROMPT_COMMAND='PS1=$PS1; echo -ne "\033]0;`hostname -s`:`pwd`\007"'
@danielcbaldwin
danielcbaldwin / log_producer.rb
Created April 20, 2012 00:01 — forked from anolson/log_producer.rb
Log streaming in ruby.
class LogProducer
attr_accessor :streams
def initialize(options = {})
@streams = Hash.new
@filename = options[:filename]
add_stream(options[:stream])
end