Skip to content

Instantly share code, notes, and snippets.

View Ultrabenosaurus's full-sized avatar

Dan Bennett Ultrabenosaurus

  • UK
View GitHub Profile
@Ultrabenosaurus
Ultrabenosaurus / get_join.php
Created August 7, 2012 11:25
A simple method to maintain current querystring when redirecting. Needed it for a WP plugin I'm making.
function get_join(){
$keys = array_keys($_GET);
$url = '?';
$first = true;
for($i = 0; $i < count($keys); $i++){
if(!$first){
$url .= '&';
}
$url .= $keys[$i].'='.$_GET[$keys[$i]];
$first = false;
@Ultrabenosaurus
Ultrabenosaurus / query_string_remove.js
Created August 7, 2012 12:59
Search the current querystring for a variable or variable/value pair and remove if found.
function query_string_remove(find, val){
// get query string, remove ? and split on &
qryStr = window.location.search.replace("?", "");
qryPrts = qryStr.split('&');
// assume search will fail, for return value
found = false;
// relies on jQuery for simplicity of this function
// use your own foreach function if you prefer
jQuery.each(qryPrts, function(i, v) {
@Ultrabenosaurus
Ultrabenosaurus / threeD.css
Created September 12, 2012 14:38
3D CSS class
.threeD{
color:rgba(0,255,255,0.5);
text-shadow: rgba(255,0,0,0.5) -4px 0px 0px;
padding-left:4px;
}
@Ultrabenosaurus
Ultrabenosaurus / clock.css
Created September 18, 2012 14:01
CSS Animations clock with seconds, minutes and hours
.loader{
color: #555;
font-family: sans-serif;
font-size: 3em;
text-align: center;
-webkit-border-radius: 50%;
border-radius: 50%;
border: 5px solid #555;
width:100px;
height:100px;
@Ultrabenosaurus
Ultrabenosaurus / changeext.php
Created September 24, 2012 13:22
recursively change file extensions
/* taken from this comment on PHP.net - http://php.net/manual/en/function.rename.php#88081 */
//changes files in $directory with extension $ext1 to have extension $ext2
//note that if file.ext2 already exists it will simply be over-written
function changeext($directory, $ext1, $ext2, $verbose = false, $testing=true) {
if ($verbose && $testing) { echo "Testing only . . . <br />";}
$num = 0;
if($curdir = opendir($directory)) {
if ($verbose) echo "Opening $directory . . .<br />";
while($file = readdir($curdir)) {
@Ultrabenosaurus
Ultrabenosaurus / objectLength.js
Created October 16, 2012 08:52
get the top-level size of a JavaScript object in all browsers
// credit to Sam (https://github.com/sambenne) for this
// saving as Gist so I don't lose it.
function objectLength(obj) {
try {
return Object.keys(obj).length;
} catch(err) {
var total = 0;
for(var k in obj) {
if(obj.hasOwnProperty(k)) {
// taken from http://stackoverflow.com/a/6969486/1734964
// saved for my own laziness
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
// taken from http://stackoverflow.com/a/3079423/1734964
// saved for my own forgetfulness
function str_shuffle(string) {
var parts = string.split('');
for (var i = parts.length; i > 0;) {
var random = parseInt(Math.random() * i);
var temp = parts[--i];
parts[i] = parts[random];
parts[random] = temp;
@Ultrabenosaurus
Ultrabenosaurus / latestTweets.js
Last active December 11, 2015 12:48
A script to pull the latest tweets from a given Twitter user, parse it for links, usernames and hashtags, then turn the date/time into a link to the tweet.
jQuery(document).ready(function(){
twitter();
});
/*
* twitter()
*
* only parameter is an object of options:
*
* profile (string) The profile to pull tweets from
/* drop shadows */
.drop-shadow.top {
box-shadow: 0 -4px 2px -2px rgba(0,0,0,0.4);
}
.drop-shadow.right {
box-shadow: 4px 0 2px -2px rgba(0,0,0,0.4);
}
.drop-shadow.bottom {
box-shadow: 0 4px 2px -2px rgba(0,0,0,0.4);
}