Skip to content

Instantly share code, notes, and snippets.

View phirschybar's full-sized avatar

Ben Hirsch phirschybar

View GitHub Profile
@wpsmith
wpsmith / sanitize_phone.php
Created June 5, 2014 17:00
PHP: Sanitize & Format US Phone Numbers
<?php
function sanitize_phone( $phone, $international = false ) {
$format = "/(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/";
$alt_format = '/^(\+\s*)?((0{0,2}1{1,3}[^\d]+)?\(?\s*([2-9][0-9]{2})\s*[^\d]?\s*([2-9][0-9]{2})\s*[^\d]?\s*([\d]{4})){1}(\s*([[:alpha:]#][^\d]*\d.*))?$/';
// Trim & Clean extension
$phone = trim( $phone );
$phone = preg_replace( '/\s+(#|x|ext(ension)?)\.?:?\s*(\d+)/', ' ext \3', $phone );
@ronaldsuwandi
ronaldsuwandi / config.fish
Last active July 30, 2021 07:54
My personal fish shell config for OS X. Supports git branch (fast git checks), virtualenv (if installed) and Kubernetes current context
function ls --description 'List contents of directory'
command ls -lFG $argv
end
function subl --description 'Launches sublime text in a new window'
command subl -n $argv
end
function code --description 'Launches visual code studio in a new window'
command code -n $argv
@imjared
imjared / lime.sh
Created October 16, 2013 16:16
Add to /usr/local/bin. Use `lime [path]` instead of `subl [path]` to open sublime projects. If a project file exists it opens and preserves project settings. Requires `subl`. In response to http://www.sublimetext.com/forum/viewtopic.php?f=3&t=14129
#!/bin/bash
projectFile=$(find $1 -name "*.sublime-project" -maxdepth 1)
echo $projectFile
if [ $projectFile ]
then
subl $projectFile
else
subl $1
fi
@oscar-broman
oscar-broman / gist:3653399
Created September 6, 2012 09:05
UTF8 encode array/object structure in PHP
<?php
function utf8_encode_deep(&$input) {
if (is_string($input)) {
$input = utf8_encode($input);
} else if (is_array($input)) {
foreach ($input as &$value) {
utf8_encode_deep($value);
}
unset($value);
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@leotsem
leotsem / binary_image.html
Created May 7, 2011 14:33
Get binary image data from remote image
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Get binary image data from remote image</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript">
$().ready(function(){