Skip to content

Instantly share code, notes, and snippets.

View phette23's full-sized avatar
🌹
"you're right, no human being would stack books like this"

Eric Phetteplace phette23

🌹
"you're right, no human being would stack books like this"
View GitHub Profile
@phette23
phette23 / is_on_campus.php
Created June 20, 2012 15:17
PHP function to check if IP falls within a range
<?php
function is_on_campus($IP = false) {
// If no IP is passed grab it from $_SERVER[]
$IP = $IP ? $IP : $_SERVER['REMOTE_ADDR'];
// Convert IP to long integer
$IPnum = ip2long($IP);
@phette23
phette23 / clearfix.css
Created July 16, 2012 19:03
Clearfix CSS Class
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
@phette23
phette23 / share-this-social-media-block.html
Created July 26, 2012 01:11
Social media icons w/ links to sharing services
<!-- not entirely necessary, rewriting this in raw JS would be trivial -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
#shareThis a {
display: inline-block;
text-decoration: none;
width: 16px; height: 16px;
/* you can grab & reuse this sprite if you like or use your own */
background: url(http://dl.dropbox.com/u/50206550/sharing-sprite.png) 0 -16px no-repeat;
}
@phette23
phette23 / assert.js
Created September 7, 2012 21:52
JavaScript Assertion
// debugging technique
// via: http://www.learncomputer.com/javascript-tricks-you-may-not-know/
function AssertException( msg ) {
this.msg = msg;
}
AssertException.prototype.toString = function() {
return 'AssertException: ' + this.msg;
}
@phette23
phette23 / pcap.sh
Created September 9, 2012 08:07
Using tcpdump to capture network traffic
sudo tcpdump -i en0 -n -s 0 -w traffic.pcap tcp or port 53
# see code.google.com/p/pcaphar/wiki/CaptureMobileTraffics
# NB: en0 is for ethernet connections, en1 for Airport
# see also support.apple.com/kb/HT3994
# can analyze .pcap output with pcapperf.appspot.com/
@phette23
phette23 / check-headers.php
Created October 23, 2012 20:09
PHP to Check HTTP Headers
<?
// php 5
print_r( get_headers( "http://example.com", 1 ) );
@phette23
phette23 / amazon2spreadsheet.js
Last active December 15, 2015 06:19
Bookmarklet to grab title, author, price, & URL from Amazon, ripe for pasting into a spreadsheet (e.g. Google Drive)
(function( $ ) {
var title, authors, price, url,
loc = document.location;
title = $( '#btAsinTitle' ).text().replace( /\s\[(Paperback|Hardcover|Bargain Price|Mass Market Paperback)\]/g, '' );
// authors' names, skip over role e.g. (editor)
if ( $( '.contributorNameTrigger' )[ 0 ] ) {
if ( $( '.contributorNameTrigger' ).length > 1 ) {
authors = $( '.contributorNameTrigger a' )[ 0 ].text();
@phette23
phette23 / current-dir-in-iterm-tab-title.sh
Last active January 4, 2024 10:20
Set the iTerm tab title to the current directory, not full path.
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# Piece-by-Piece Explanation:
# the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
# iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
# the $PROMPT_COMMAND environment variable is executed every time a command is run
# see: ss64.com/bash/syntax-prompt.html
@phette23
phette23 / fluid-width-youtube-vid.html
Last active December 15, 2015 15:08
Markup for making a fluid-width YouTube video embed. Better to do it in markup than use FitVids, where the markup was taken from.
<!-- just replace {{id}} with the video's ID
e.g. 9bZkp7q19f0 -->
<div style="width:100%;position:relative;padding:0;padding-top:75%">
<iframe
style="position:absolute;top:0;left:0;width:100%;height:100%;"
src="http://www.youtube-nocookie.com/embed/{{id}}?rel=0"
frameborder="0" allowfullscreen mozallowfullscreen webkitallowfullscreen>
</iframe>
</div>
@phette23
phette23 / top-10-commands.sh
Created April 14, 2013 19:59
Results of my "top 10 BASH commands used"
# Top 10 BASH commands used
# from stackoverflow.com/questions/68372/what-is-your-single-most-favorite-command-line-trick-using-bash#answer-68390
function top10() {
history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $3}' | sort | uniq -c | sort -nr | head
}
1393 gs - alias for git status
1272 g - alias for git
1121 l - alias for ls -l
1003 - can't explain this...why would an empty space show up as a command? Bug in the top10 function maybe