Skip to content

Instantly share code, notes, and snippets.

@danharper
danharper / 1-jquery.js
Last active December 14, 2015 09:19
From jQuery to plain JavaScript
(function() {
// written with jQuery
$('.dribbble-link img').each(function(i, e) {
e = $(e);
e.attr('src', e.attr('src').replace('_teaser', ''));
});
$('ol.dribbbles li.group').css('width', '420px');
@danharper
danharper / 1-TestCase.php
Created March 1, 2013 19:21
Laravel 4 Mocking
<?php
class TestCase extends Illuminate\Foundation\Testing\TestCase {
// ...
public function appMock($name)
{
$mock = Mockery::mock($name);
App::instance($name, $mock);
@danharper
danharper / classifier.js
Last active December 17, 2015 11:39
Portsmouth University Classification Calculator
/*
run with:
portsmouthClassifier.classify(marks);
*/
var portsmouthClassifier = (function() {
var totalCredits = function(year) {
return _.reduce(year, function(memo, unit) {
return memo + unit.credits;
#!/bin/sh
#
# This hook does two things:
#
# 1. update the "info" files that allow the list of references to be
# queries over dumb transports such as http
#
# 2. if this repository looks like it is a non-bare repository, and
# the checked-out branch is pushed to, then update the working copy.
# This makes "push" function somewhat similarly to darcs and bzr.
@danharper
danharper / download.sh
Created August 9, 2013 11:45
Download all UoP graduation photos from July 19th at 2:30. Switch the initial number for other days.
wget https://www.successphotography.com/traceimagefreepp.php?gpr=131196571000{1..9}&gpi= && \
wget https://www.successphotography.com/traceimagefreepp.php?gpr=13119657100{10..99}&gpi= && \
wget https://www.successphotography.com/traceimagefreepp.php?gpr=1311965710{100..342}&gpi=
<?php
$x = false or true;
// => true
var_export($x);
// => false

$y = false || true;
// => true
var_export($y);
@danharper
danharper / background.js
Last active March 30, 2024 18:25
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
@danharper
danharper / a.js
Created January 14, 2014 18:23
XHR upload progress
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', function(e) {
var percent = parseInt(e.loaded / e.total * 100, 10)+'%';
console.log('progress', percent);
}, false);
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log('done!');
@danharper
danharper / example.php
Created January 23, 2014 11:51
Laravel/Eloquent Single Table Inheritance Trait
<?php
class Category extends Eloquent {
use EloquentSingleTableInheritenceTrait;
protected function singleTableInheritanceMpa()
{
return [
1 => 'InventoryCategory',
@danharper
danharper / BaseCollection.php
Created January 24, 2014 12:34
Laravel/Eloquent Collection method to sort by a comma-separated string of IDs. Any models which do not appear in the given order are added to the end in ID order.
<?php
use Illuminate\Database\Eloquent\Collection;
class BaseCollection extends Collection {
public function sortByOrder($order, $delimeter = ',')
{
$order = is_array($order) ? $order : explode($delimeter, $order);