Skip to content

Instantly share code, notes, and snippets.

View stephenparish's full-sized avatar

Stephen Parish stephenparish

View GitHub Profile
#!/bin/sh
# Check if the individual developer has his own hook
CMD_NAME=`basename $0`
if [ -f $GIT_DIR/hooks/personal/$CMD_NAME ]
then
# If so, run it. $@ passes all the command line arguments passed to this function
# If the personal hook fails, fail this one as well
if ! $GIT_DIR/hooks/personal/$CMD_NAME $@
then
// Provides a device_scale class on iOS devices for scaling user
// interface elements relative to the current zoom factor.
//
// http://37signals.com/svn/posts/2407-device-scale-user-interface-elements-in-ios-mobile-safari
// Copyright (c) 2010 37signals.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@frankshearar
frankshearar / fake-http-context.cs
Created February 21, 2011 21:28
A Moq-using fake HTTP context to test controllers.
public HttpContextBase FakeHttpContext() {
var context = new Mock<HttpContextBase>();
var files = new Mock<HttpFileCollectionBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
var user = new Mock<IPrincipal>();
var identity = new Mock<IIdentity>();
request.Setup(req => req.ApplicationPath).Returns("~/");
@juliocesar
juliocesar / best-localStorage-polyfill-evar.js
Created April 18, 2011 23:19
This is the best localStorage polyfill in the world
// I mean, seriously, localStorage is supported even by your mum. How about instead of
// casing the feature out, you give users in-memory (stale) storage instead?
// If they close your application, they deserve to lose data anyway.
// if (!('localStorage' in window)) {
if (!Modernizr.localstorage) {
window.localStorage = {
_data : {},
setItem : function(id, val) { return this._data[id] = String(val); },
getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
@alimbada
alimbada / Wake.ps1
Last active February 8, 2024 21:03
PowerShell script for sending Wake On LAN magic packets to given machines/MAC address(es)
#######################################################
##
## Wake.ps1, v1.0, 2013
##
## Adapted by Ammaar Limbada
## Original Author: Matthijs ten Seldam, Microsoft (see: http://blogs.technet.com/matthts)
##
#######################################################
<#
@rais38
rais38 / gist:5766980
Created June 12, 2013 16:35
Create patch from stash
git stash show -p stash@{0} > Stash0.patch
@iheanyi
iheanyi / NowArrayAdapter.java
Last active February 10, 2019 17:32
Google Now Cards Layout XML. list_item.xml can be customized to your heart's content . . . Also, you can implement the following with DragSortListView for swiping to delete, reordering, and whatnot.
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
@pboos
pboos / annotation-processor-build.gradle
Last active August 7, 2020 06:38
Gradle stuff for Android
configurations {
apt
}
dependencies {
compile 'com.squareup.dagger:dagger:1.1.0'
apt 'com.squareup.dagger:dagger-compiler:1.1.0'
}
android.applicationVariants.all { variant ->
@tbroyer
tbroyer / README.md
Last active May 25, 2016 13:46
Error-prone in Gradle

UPDATE: This is now available as a plugin https://github.com/tbroyer/gradle-errorprone-plugin

To use it, just add the following to your build.gradle and it'll change all JavaCompile tasks to use the error-prone compiler:

apply from: 'https://gist.github.com/tbroyer/6847494/raw/errorprone.gradle'
@haacked
haacked / code-review-checklist.md
Last active March 9, 2020 19:28
Code Review Checklist

General

  1. Unit tests: Review unit tests first. Unit tests are a fantastic way to grasp how code is meant to be used by others and to learn what the expected behavior is. Are there any test gaps that should be there?
  2. Method arguments" Make sure arguments to methods make sense and are validated. Mentally test boundary conditions and edge cases.
  3. Null References" (Yah yah, we know. Use F# and this goes away. We get it already.) Null references are a bitch and it’s worth looking out for them specifically.
  4. Conventions Consistency" Make sure naming, formatting, etc. follow our conventions and are consistent. I like a codebase that’s fairly consistent so you know what to expect.
  5. Disposables: Make sure disposable things are disposed. Look for usages of resources that should be disposed but are not.
  6. Security: There is a whole threat and mitigation review process that falls under this bucket. In simple terms, ask yourself how this code could be exploited. The [STRIDE Threat Mo