Skip to content

Instantly share code, notes, and snippets.

@joshuaflanagan
joshuaflanagan / gist:523aeec5fceb3bc75691
Created December 17, 2014 01:46
Recover a branch when you know the SHA, but don't have it locally
http -v -a username:password POST https://api.github.com/repos/owner/repo/git/refs ref="refs/heads/recovered_branch" sha="290b2090a741d35edd67f15c74b2d43299df8995"
git fetch
git checkout recovered_branch
@joshuaflanagan
joshuaflanagan / pngcheck.rb
Last active August 29, 2015 14:13
Parse PNG file
# http://www.w3.org/TR/PNG/#5DataRep
class PNGCheck
def initialize(path)
@path = path
end
def check_all!
expected_signature = [137, 80, 78, 71, 13, 10, 26, 10]
file.seek 0
signature_data = file.read(8)
def no_surprises!
ActiveRecord::Base.class_eval do
include SkipsValidations
include SkipsCallbacks
end
end
module SkipsValidations
def perform_validations(*)
true
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
namespace DovetailCRM.Core.Web.Mapping
{
public static class AutoMapperExtensions
{
public static void CreateMapsForSourceTypes(this IConfiguration configuration, Func<Type, bool> filter, Func<Type, Type> destinationType, Action<IMappingExpression, Type, Type> mappingConfiguration)
menuLine.bind("click",function(){
if (($(voice).attr("action") || $(voice).attr("href")) && !isDisabled){
var target=$(voice).attr("target")?$(voice).attr("target"):"_self";
if ($(voice).attr("href") && $(voice).attr("href").indexOf("javascript:")>-1){
$(voice).attr("action",$(voice).attr("href").replace("javascript:",""));
}
var link=$(voice).attr("action")?$(voice).attr("action"):"window.open('"+$(voice).attr("href")+"', '"+target+"')";
if (!$(voice).attr("href") || ($(voice).attr("href") && $(voice).attr("href").indexOf("javascript:")>-1)){
$(voice).removeAttr("href");
}
public class CustomViewVirtualPathProvider : VirtualPathProvider
{
public override bool FileExists(string virtualPath)
{
return File.Exists(HostingEnvironment.MapPath(virtualPath));
}
public override VirtualFile GetFile(string virtualPath)
{
var customizedVirtualPath = virtualPath.Replace(HostingEnvironment.ApplicationVirtualPath, HostingEnvironment.ApplicationVirtualPath + "/CustomViews/");
desc "Generate the database schema"
task :db do
$:.unshift('.\src\MyApp\bin') # Add the website bin folder to the load_path so that assembly dependencies are found
require 'MyApp' # MyApp is my ASP.NET web app assembly DLL
MyApp::Database.BuildSchema # Database.BuildSchema is a static method
puts 'Database rebuilt'
end
##### Using ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
C:\code>irb
irb(main):001:0> include FileTest
=> Object
irb(main):002:0> exists? 'foo'
=> false
irb(main):003:0>
### Using IronRuby 1.0
C:\code>ir
public static HtmlTag TableFor<T>(this IFubuPage view, IEnumerable<T> data, params string[] columns) where T : class
{
var properties = typeof(T).GetProperties();
// optionally limit the columns to display
if (columns.Length > 0) properties = properties.Where(p => columns.Contains(p.Name)).ToArray();
var table = new HtmlTag("table");
var header = new HtmlTag("thead");
table.Child(header);
foreach (var property in properties)
@joshuaflanagan
joshuaflanagan / restoredb.sql
Created July 14, 2010 16:45
Restore a SQL Server database
ALTER DATABASE mydbname SET SINGLE_USER With ROLLBACK IMMEDIATE
RESTORE DATABASE mydbname FROM DISK = 'c:\path\to\file.bak' WITH REPLACE