Skip to content

Instantly share code, notes, and snippets.

@malsup
malsup / jsonp
Created March 20, 2009 02:58
$.getJSONP
// fn to handle jsonp with timeouts and errors
// hat tip to Ricardo Tomasi for the timeout logic
$.getJSONP = function(s) {
s.dataType = 'jsonp';
$.ajax(s);
// figure out what the callback fn is
var $script = $(document.getElementsByTagName('head')[0].firstChild);
var url = $script.attr('src') || '';
var cb = (url.match(/callback=(\w+)/)||[])[1];
@jschementi
jschementi / git-tfs.md
Created January 26, 2010 08:35
Using TFS and GIT together

Using TFS and GIT together

What if your team uses TFS, but you want offline support? You can have a Git repo as well, but then getting your changes to TFS is burdensome. Here’s where a GIT to TFS bridge would be handy.

Setting up your repo

Here’s how to keep a TFS repository foo, and a GIT repository bar, in sync. First step is you need to create a new TFS workspace:

cd \

tf workspace /new /noprompt Foo

@smithrobs
smithrobs / gist:1076027
Created July 11, 2011 14:59
Full trust of all SSL certs
// callback used to validate the certificate in an SSL conversation
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors policyErrors)
{
bool result = false;
if (cert.Subject.ToUpper().Contains("YourServerName"))
{
result = true;
}
return result;
@SteveDunn
SteveDunn / EnumMapper.cs
Created August 17, 2011 21:25
Enum Mapper in C#
public class EnumMapper : IDisposable
{
readonly Dictionary<Type, Dictionary<string, object>> _stringsToEnums =
new Dictionary<Type, Dictionary<string, object>>( ) ;
readonly Dictionary<Type, Dictionary<int, string>> _enumNumbersToStrings =
new Dictionary<Type, Dictionary<int, string>>( ) ;
readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim( ) ;
@RobertWithP
RobertWithP / HttpWebRequestWrapper.cs
Created December 15, 2011 12:23
Testdriven Wrapper for HttpWebRequest
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.IO;
using Moq;
using System.Runtime.Serialization;
@jexchan
jexchan / visualization_in_js.md
Created December 25, 2011 13:48 — forked from entaroadun/visualization_in_js.md
README:Visualization using Javascript on Github
@AdamLJohnson
AdamLJohnson / EnumerableExtensions.cs
Created January 31, 2012 17:28
LINQ using Wildcards
// Source: http://stackoverflow.com/questions/3102250/linq-search-using-wildcards-character-like
public static class EnumerableExtensions
{
public static IEnumerable<T> MatchesWildcard<T>(this IEnumerable<T> sequence, Func<T,string> expression, string pattern)
{
var regEx = WildcardToRegex(pattern);
return sequence.Where(item => Regex.IsMatch(expression(item), regEx));
}
public static string WildcardToRegex(string pattern)
@antimatter15
antimatter15 / algorithm.pseudo
Created February 16, 2012 03:22
Pseudocode to Graphviz Converter
Place phone call.
Home?
Leave message
Wait for callback
"Would you like to share a meal"
"Would you like to share a meal"
What is the response (A) ?
"Do you enjoy a hot beverage"
What is the response (B) ?
n = 0
@Zoramite
Zoramite / maintenance.sh
Created March 14, 2012 21:25
Git Maintenance Commands
# Verifies the connectivity and validity of the objects in the database
git fsck —unreachable
# Manage reflog information
git reflog expire —expire=0 —all
# Pack unpacked objects in a repository
git repack -a -d -l
# Prune all unreachable objects from the object database
@hickford
hickford / group-adjacent-by.cs
Created April 1, 2012 16:58
GroupAdjacentBy method for .NET in C#
public static class LINQExtensions
{
public static IEnumerable<IGrouping<TKey, TElement>> GroupAdjacentBy<TElement, TKey>(this IEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey> comparer=null)
{
comparer = comparer ?? EqualityComparer<TKey>.Default;
List<TElement> elements = null;
TKey key = default(TKey);
TKey lastKey = default(TKey);
foreach (var x in source)
{