Skip to content

Instantly share code, notes, and snippets.

@antonydenyer
antonydenyer / gist:1ea0fdcde8dc02f49f5c
Last active August 29, 2015 14:06
Restore deleted file from git
Restore deleted file from git
git log --diff-filter=D --summary
git checkout xxxx~1 filename
@antonydenyer
antonydenyer / qDecorator.js
Last active November 23, 2017 12:50
fix IE8 support for catch and finally in angularjs $q service (http://www.antonydenyer.co.uk/blog/2014/08/22/angularjs-decorator-to-support-ie8-catch/)
(function () {
"use strict";
app.config(function ($provide) {
$provide.decorator('$q', function ($delegate) {
// http://dorp.io/blog/extending-q-promises.html
function decoratePromise(promise) {
promise._then = promise.then;
promise.then = function (thenFn, errFn, notifyFn) {
var p = promise._then(thenFn, errFn, notifyFn);
var app = angular.module('MyApp', []);
app.controller('MyController', function($scope, myService) {
myService.getSomething()
.then(function(response) {
$scope.viewModel = response;
});
});
describe('MyController', function () {
var controller, scope, myService, q;
beforeEach(function () { module('MyApp'); });
beforeEach(inject(function ($controller, $rootScope, $q) {
controller = $controller;
scope = $rootScope.$new();
myService = jasmine.createSpyObj('myService', ['getSomething']);
q = $q;
@antonydenyer
antonydenyer / gist:11177414
Created April 22, 2014 12:38
my inject from this morning
class Array
def skip_first?(accumulator)
return 1 if accumulator.nil?
return 0 unless accumulator.nil?
end
def my_inject(accumulator = nil)
start = skip_first? accumulator
accumulator ||= self.first
@antonydenyer
antonydenyer / Id not populated
Created February 18, 2014 16:20
Automatic id generation and mapping _id NEST
using System;
using System.Linq;
using NUnit.Framework;
namespace Nest.AutoId
{
[ElasticType(Name = "data", IdProperty = "Id")]
public class DataForGet : DataForIndex
{
public string Id { get; set; }
var buttons = $(".js-follow-btn .follow-text :visible"),
interval = setInterval(function(){
var btn = $(buttons.splice(0, 1));
console.log("Clicking:", btn);
btn.click();
if (buttons.length === 0) {
clearInterval(interval);
}
}, 100);
@antonydenyer
antonydenyer / Update-Packages
Created November 27, 2013 10:14
Update all packages in a solution from nuget
Get-ChildItem -path '.' -Recurse -Include 'packages.config' |
Select-Xml -xpath '//package/@id' |
Select-Object -ExpandProperty Node |
Select-Object -ExpandProperty value |
Sort-Object -Unique |
ForEach-Object {
foreach($arg in $MyInvocation.UnboundArguments)
{
if($_ -like $arg)
{
@antonydenyer
antonydenyer / OctoChef.ps1
Last active December 20, 2015 06:39
Abusing Octopus Deploy with OctoChef Deploy
param(
[parameter(Mandatory = $true)]
$packageName
)
$currentDirectory=$pwd
function CreateTempDir
{
$tmpDir = [System.IO.Path]::GetTempPath()
$tmpDir = [System.IO.Path]::Combine($tmpDir, [System.IO.Path]::GetRandomFileName())
@antonydenyer
antonydenyer / NinjectIocAdapter
Created January 23, 2013 17:35
NinjectIocAdapter with IEnumerable Resolution Looking for better ways to do this
public class NinjectIocAdapter : IContainerAdapter
{
private readonly IKernel _kernel;
public NinjectIocAdapter(IKernel kernel)
{
_kernel = kernel;
}
public T TryResolve<T>()