Skip to content

Instantly share code, notes, and snippets.

@jmcd
jmcd / gist:5684950
Created May 31, 2013 13:26
Make a square image
private Image MakeSquareImage(Image source, int targetLength)
{
var sourceBitmap = new Bitmap(source);
var sourceLength = Math.Min(source.Size.Height, source.Size.Width);
var cropRect = new Rectangle((source.Size.Width - sourceLength)/2, (source.Size.Height - sourceLength)/2, sourceLength, sourceLength);
var squaredSource = sourceBitmap.Clone(cropRect, sourceBitmap.PixelFormat);
var result = new Bitmap(squaredSource, new Size(targetLength, targetLength));
@jmcd
jmcd / pagination reduction.js
Created July 1, 2013 13:04
Reduce the number of links in bootstrap pagination
$(function () {
var radius = 4;
var replacementForHiddenContent = "<li><a>...</a></li>";
var $pages = $(".js-page");
var $activePage = $pages.filter(".active");
var indexOfActive = $pages.index($activePage);
@jmcd
jmcd / gist:6000788
Created July 15, 2013 15:16
Format many XML files in a directory
find . -maxdepth 1 -type f -exec xmllint --format -o formatted/{} {} \;
@jmcd
jmcd / gist:6260509
Created August 18, 2013 08:08
Sublime/boost underscore to came case
_((\w)([^_]*))
\U$2\L$3
@jmcd
jmcd / IIS JSON Compression
Created September 13, 2013 15:07
Add dynamic JSON compression to IIS
Install the Compression/DynamicConmpression role with the Server Manager.
Check the httpCompression/dynamicTypes/dynamicTypes element in %windir%\System32\inetsrv\config\applicationhost.config, if application/json is missing, do the following:
%windir%\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost
@jmcd
jmcd / MyScene.m
Created September 18, 2013 07:37
Small SpriteKit demo
#import "MyScene.h"
@interface MyScene () <SKPhysicsContactDelegate>
@end
@implementation MyScene {
NSMutableSet *_notCrashedPhysicsBodies;
}
static const uint32_t carCategory = 0x1 << 0;
@jmcd
jmcd / XOp.h
Created September 20, 2013 12:29
An NSOperation that controls its own finish - useful for operations that use async code (NSConnection etc.). Override start (and call base), then call [self finish] when done.
#import <Foundation/Foundation.h>
@interface XOp : NSOperation
- (void)finish;
@end
@jmcd
jmcd / ArrayChunker.cs
Created March 10, 2014 12:37
Split array into chunks
public static class ArrayChunker<T>
{
public static T[][] Chunk(T[] sourceArray, int chunkLength)
{
var numberOfFullBuffers = sourceArray.Length/chunkLength;
var lengthOfRemainderBuffer = sourceArray.Length%chunkLength;
var hasRemander = lengthOfRemainderBuffer > 0;
var numberOfBuffers = numberOfFullBuffers +( hasRemander ? 1 : 0);
@jmcd
jmcd / filtered.js
Created July 16, 2014 11:26
jQuery plugin to filter tables/whatever
(function ($) {
$.fn.filtered = function (options) {
var roots = this;
var displayProperty = $(roots).first().css('display');
var elementContentArrays = [];
@jmcd
jmcd / mkappicons.swift
Created October 27, 2014 17:11
Create all the different sized iOS App Icons from a single source image
#!/usr/bin/xcrun swift
import Cocoa
import AppKit
import CoreGraphics
class Spec {
let pointSize: Int;
let scales: [Int]