Skip to content

Instantly share code, notes, and snippets.

View SamFleming's full-sized avatar

Sam Fleming SamFleming

View GitHub Profile
@SamFleming
SamFleming / mod_rewrite redirection check
Created March 17, 2012 11:24
mod_rewrite - Not from a redirect
RewriteCond %{ENV:REDIRECT_STATUS} ^$
@SamFleming
SamFleming / uri.js
Created April 22, 2012 09:51 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@SamFleming
SamFleming / hash_pbkdf2.php
Created May 29, 2012 11:19 — forked from mattattui/hash_pbkdf2.php
PHP PBKDF2 implementation
<?php
/* PHP PBKDF2 implementation
*
* PBKDF2 is a key derivation function defined in RFC2898. It's used to
* generate longer and more secure passwords from short, human-entered
* passwords. The number of rounds can be increased to keep ahead of
* improvements in CPU/GPU performance.
*
* You should use a different salt for each password (it's safe to store it
@SamFleming
SamFleming / pagination.ctp
Created June 8, 2012 10:24 — forked from slywalker/pagination.ctp
pagination element for CakePHP on twitter bootstrap - without first/last and using htmlentities
<?php
if (!isset($modules)) {
$modulus = 11;
}
if (!isset($model)) {
$models = ClassRegistry::keys();
$model = Inflector::camelize(current($models));
}
?>
<div class="pagination">
@SamFleming
SamFleming / grooveshark_fluid.js
Created July 9, 2012 16:50
Grooveshark for Fluid
// ==UserScript==
// @name Grooveshark for Fluid
// @namespace clintxs@gmail.com
// @description Adds Growl notifications and iTunes-style track info to the dock menu. Also adds the controls: Play/Pause, Next, and Previous.
// @include http://*grooveshark.com/*
// @author Clint Strong
// ==/UserScript==
(function () {
if (window.fluid) {
@SamFleming
SamFleming / html5_template.html
Created July 17, 2012 09:19 — forked from nathansmith/html5_template.html
Simple HTML5 Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Untitled</title>
<link rel="stylesheet" href="" />
</head>
<body>
</body>
@SamFleming
SamFleming / gist:3350252
Created August 14, 2012 15:22
CakePHP custom checkbox values
<?php
echo $this->Form->checkbox('FIELD', array('value' => 'Checkbox checked', 'hiddenField' => 'Checkbox HAS NOT been checked'));
@SamFleming
SamFleming / gimage-search.js
Created August 27, 2012 17:15
Ajax google image search - random thumbnail
$.ajax({
dataType: "jsonp",
url: 'http://ajax.googleapis.com/ajax/services/search/images',
data: {
v: "1.0",
rsz: 8,
q: "airplane"
},
success: function ( json ) {
var rand = Math.floor(Math.random() * json.responseData.results.length),
@SamFleming
SamFleming / gist:6250460
Created August 16, 2013 14:35
Removing a git submodule. Taken from http://stackoverflow.com/a/1260982/727236

Removing a git submodule

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Run git rm --cached path_to_submodule (no trailing slash).
  5. Run rm -rf .git/modules/submodule_name
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
<style id="jsbin-css">
body {
background: #8bbec9;
background: -moz-linear-gradient(left, #8bbec9 0%, #97cbd6 100%);