Skip to content

Instantly share code, notes, and snippets.

View achvaicer's full-sized avatar

Alberto Chvaicer achvaicer

View GitHub Profile
@anaisbetts
anaisbetts / .gitattributes
Created December 3, 2014 16:26
USE THIS GITATTRIBUTES FOR EVERY NEW PROJECT FOREVER AND EVER
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
@jmmcduffie
jmmcduffie / behaviors.js
Last active August 29, 2015 13:56
Progressively Enhanced Single-Page Navigation
// Add an event listener to the document
$(document).on( "click", "a[data-behavior='scrollTo']", function(event) {
// Check for a fragment on the clicked link
// `this.hash` = the fragment identifier
if ( this.hash !== "" ) {
// Animate the viewport's scroll position
$("html, body").animate({ scrollTop: $( this.hash ).offset().top }, 500);
@bradwilson
bradwilson / Cacheability.cs
Created January 23, 2014 20:53
Using chaining to create cached results in ASP.NET Web API v2
public enum Cacheability
{
NoCache,
Private,
Public,
}
@dvdsgl
dvdsgl / CachedFunc.cs
Last active December 13, 2015 17:38
Quickly create Funcs that memoize expensive computations.
// Quickly create Funcs that memoize expensive computations.
//
// In this example, ExpensiveMethod is only called once!
//
// var cached = CachedFunc.Create ((int x, string y) => x + ExpensiveMethod (y));
// for (int i = 0; i < 1000; i++)
// cached (123, "hello");
public static class CachedFunc
{
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
var inputs = new[] { "http://www.google.com", "http://www.yahoo.com", "http://www.aol.com", };
var results = await inputs.AsAsync()
.WhereAsync(async x => await IsPageInTop10WebSitesByTraffic(x))
.SelectAsync(async x => await DownloadPageAsync(x))
.GetResults();
@jongalloway
jongalloway / RecursiveReplace.ps
Created December 29, 2011 07:56
Recursive replace in files (PowerShell)
$find = 'jquery-1\.4\.4'
$replace = 'jquery-1\.5\.1'
$match = '*.cshtml' , '*.vbhtml'
$preview = $true
foreach ($sc in dir -recurse -include $match | where { test-path $_.fullname -pathtype leaf} ) {
select-string -path $sc -pattern $find
if (!$preview) {
(get-content $sc) | foreach-object { $_ -replace $find, $replace } | set-content $sc
}