Skip to content

Instantly share code, notes, and snippets.

View Ultrabenosaurus's full-sized avatar

Dan Bennett Ultrabenosaurus

  • UK
View GitHub Profile
@Ultrabenosaurus
Ultrabenosaurus / git-lg
Last active August 29, 2015 14:04
Visual Git Commit History
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit"
@Ultrabenosaurus
Ultrabenosaurus / one-page.md
Last active December 18, 2015 21:38
why I will never agree with one-page, scroll-to-your-content sites

Take a simple 5-page site that just covers who you are, what you do, some example projects and contact info or something. I bookmark one of those pages so I can read it later when I have more time. I get home, open the bookmark and the page loads with only the relevant HTML, CSS and JS. Done.

Say that site is converted into a single-page, super-scroll site and the content equivalent to the page I bookmarked happens to have been placed at the bottom of this page. Now, when I open the bookmark (assuming there is a 301 set up correctly) I have to wait for the content from all the other pages to load as well before the page is ready. While this is happening I might start reading my content only to have the page grow as images load in, pushing my content down and making me lose my place. There might be a larger amount of CSS and JS as well because previously page-specific code will now need to be loaded every time, regardless of if it is needed for the content the user wants, which could hurt functionality.

It i

@Ultrabenosaurus
Ultrabenosaurus / social-stats.php
Created June 24, 2013 06:57
Get the count of tweets, likes and +1's for a URL. Saved from this repo - https://github.com/whyisjake/Social-Stats - but I didn't feel it deserved an actual repo so I saved it as a gist, and also added a function that returns all three stats for you. Currently relies on some WordPress functions, will need to alter that at some point.
<?php
function make_get_tweets( $url ) {
$json_string = wpcom_vip_file_get_contents( 'http://urls.api.twitter.com/1/urls/count.json?url=' . $url );
$json = json_decode($json_string, true);
return intval( $json['count'] );
}
function make_get_likes( $url ) {
$json_string = wpcom_vip_file_get_contents('http://graph.facebook.com/?ids=' . $url);
@Ultrabenosaurus
Ultrabenosaurus / overlay.html
Last active December 14, 2015 09:18
A super-simple overlay system with a message box.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Simple Overlay</title>
<style>
#overlay{
position:fixed;
top: 0px;
bottom: 0px;
/* 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);
}
@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
// 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;
// taken from http://stackoverflow.com/a/6969486/1734964
// saved for my own laziness
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
@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)) {
@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)) {