This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
// jQuery plugin definition | |
$.fn.bytesInput = function () { | |
$(this).filter('input[type="text"]').each(function() { | |
$(this).data('bytesInput', true); | |
}); | |
return this; | |
}; | |
var origHook; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import Image | |
def autocrop_image(image, border = 0): | |
# Get the bounding box | |
bbox = image.getbbox() | |
# Crop the image to the contents of the bounding box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object = { foo: 42, bar: 43, baz: 44 }; | |
Object.keys(object).sort().every(function (key) { | |
console.log(key + ' -> ' + object[key]); | |
// Keep going | |
return true; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
say+(Fizz)[++$_%3].Buzz x/.?[50]$/||$_ until$` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extracts the browser name and version number from user agent string. | |
* | |
* @param userAgent | |
* The user agent string to parse. If not specified, the contents of | |
* navigator.userAgent are parsed. | |
* @param elements | |
* How many elements of the version number should be returned. A | |
* value of 0 means the whole version. If not specified, defaults to | |
* 2 (major and minor release number). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Perl oneliner (with a shell alias) that calculates the average running pace based on distance and time | |
# Examples: | |
# pace 5 28:05 # 5 kilometres, 28 minutes and 5 seconds | |
# pace 10.5 45:28 # 10.5 kilometres, 45 minutes and 28 seconds | |
# pace 42.195 2:03:38 # Marathon, 2 hours, 3 minutes and 38 seconds (current WR) | |
alias pace="perl -e 'map{\$t+=\$_*60**\$i++}reverse split/:/,pop;\$t/=pop;printf\"%d:%02d\n\",\$t/60,\$t%60'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Cwd; | |
use File::Temp; | |
# Remember the current directory | |
my $oldcwd = getcwd; | |
# Create a temporary directory | |
my $dir = File::Temp->newdir; | |
# Go to the temporary directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
{ | |
package Person; | |
use Moo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil, tempfile | |
from os import path | |
import unittest | |
class TestExample(unittest.TestCase): | |
def setUp(self): | |
# Create a temporary directory | |
self.test_dir = tempfile.mkdtemp() | |
def tearDown(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageChops | |
def img_identical(file1, file2): | |
""" | |
Take two image file names and return a boolean value indicating if the | |
images are identical. | |
""" | |
im1 = Image.open(file1) | |
im2 = Image.open(file2) | |
return ImageChops.difference(im1, im2).getbbox() is None |
OlderNewer