Skip to content

Instantly share code, notes, and snippets.

@josephwegner
josephwegner / togglePanels
Created March 21, 2011 20:22
Switches between gnome-panel configurations for variable monitor configurations.
Main() {
NR_OF_MONITORS=$(xrandr | grep -v disconnected | grep -c connected)
if [ $NR_OF_MONITORS = 1 ]; then
oneMon
fi
if [ $NR_OF_MONITORS = 2 ]; then
twoMon
fi
@josephwegner
josephwegner / cpp.scaff
Created June 18, 2011 03:01
Quickly and Easily create scaffolding for whatever language you want
/******************
Name:
Project:
Purpose:
******************* /*
#include <iostream>
using namespace std;
@josephwegner
josephwegner / jquery-hideIdleCursor.js
Created September 20, 2011 12:31
Hide your cursor on a web page when it is idle. Great if you're using a web page for some sort of TV Display and don't want the cursor messing things up.
//Requires jQuery - http://code.jquery.com/jquery-1.6.4.min.js
$(document).ready(function() {
var idleMouseTimer;
var forceMouseHide = false;
$("body").css('cursor', 'none');
$("#wrapper").mousemove(function(ev) {
if(!forceMouseHide) {
$("body").css('cursor', '');
@josephwegner
josephwegner / exampleTable.html
Created October 27, 2011 00:14
A quick table sorter for Raphie
<table id="list">
<tr>
<th class='sort alpha' id='0'>Email Address</th>
<th class='sort date' id='1'>Date Added</th>
<th class='sort alpha' id='2'>Referral Link</th>
<th class='sort num' id='3'># Referrals</th>
<th>Aprove Users</th>
<th></th>
</tr>
<tr>
@josephwegner
josephwegner / phpEvenCheck.php
Created April 27, 2012 12:58
Is Number Even
<?
function isEven($g, $isIt = false) {
$g--;
$isIt = !$isIt;
if($g <= 0) {
if($isIt === TRUE) {
echo "$ g is even!";
return true;
} elseif($isIt === FALSE) {
@josephwegner
josephwegner / gist:3087360
Created July 11, 2012 01:31
Change img urls to point to CDN
var html = "<body><div id='test'><script type='text/javascript' src='http://testScript.com'></script><img src='http://www.google.com' /><img class='test1' src='http://www.test.com' /><img src='http://woot.com' class='test2' /></div></body>";
html.replace(/<img [^>]*src=["']([A-Za-z0-9\%\?\=\&\:\/\\\.]+)["']/gi, function(full,match) {
return full.replace(match, "http://my.cdn.com?url=" + escape(match))
});
//Outputs:
//"<body><div id='test'><script type='text/javascript' src='http://testScript.com'></script><img src='http://my.cdn.com?url=http%3A//www.google.com' /><img class='test1' src='http://my.cdn.com?url=http%3A//www.test.com' /><img src='http://my.cdn.com?url=http%3A//woot.com' class='test2' /></div></body>"
@josephwegner
josephwegner / benchmark
Created July 11, 2012 03:35
Benchmark PhantomJS against cURL
#!/bin/bash
PREPHANTOMTIME=`date +%s%N | cut -b1-13`
count="0"
while [ $count -lt $2 ];
do
phantomjs --load-images=no ./timer.js "$1" > /dev/null 2>&1
count=$[$count + 1]
echo -ne "."
done
@josephwegner
josephwegner / score.js
Created July 27, 2012 14:58
Visual Scoring of Main Content via Javascript
/*
* Really all this does so far is give a score based on how much the element protrudes off the center. Center content is usually the focus
*/
function getOffset( el ) {
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
@josephwegner
josephwegner / scrape.js
Created July 27, 2012 22:03
Scrape with PhantomJS
var page = require('webpage').create();
if(phantom.args.length < 1) {
phantom.exit();
} else {
var address = phantom.args[0];
page.onError = function() { };
page.open(address, function(status) {
@josephwegner
josephwegner / console.js
Created August 7, 2012 15:23
Safe console.log
if(console.log && !logsOn) { //If console.log exists, override it with you safe log check
console.log = function() { };
}