Skip to content

Instantly share code, notes, and snippets.

View pedroreys's full-sized avatar

Pedro Reys pedroreys

View GitHub Profile
@pedroreys
pedroreys / Message.cs
Created April 12, 2013 20:18
Defining a custom JsonConverter and using it with the built-in JsonConverterAttribute
public class Message
{
[JsonConverter(typeof(SHA256StringJsonConverter))]
public string Password { get; set; }
}
@pedroreys
pedroreys / gist:5292915
Created April 2, 2013 15:03
find the potential bug
public static class Foo
{
private static async Task DelayAsync()
{
await Task.Delay(1000);
}
public static void Test()
{
var delayTask = DelayAsync();
@pedroreys
pedroreys / Login.xaml.cs
Created March 21, 2013 16:54
WP8 NavigationService::Navigate only takes an URI as an argument. It will then throw if you try to navigate to a view that has ctor dependencies. Call on line 14 of Welcome.xaml.cs will throw.
public partial class Login : PhoneApplicationPage
{
ILoginService _service;
public Login(ILoginService service)
{
this.InitializeComponent();
_service = service;
}
public static class TypeExtensions
{
public static bool IsAssignableToGenericType(this Type givenType, Type genericType)
{
var interfaceTypes = givenType.GetInterfaces();
if (interfaceTypes.Any(it => it.IsGenericType && it.GetGenericTypeDefinition() == genericType))
{
return true;
}
@pedroreys
pedroreys / Request
Created October 30, 2012 18:50
Creating an account on Buddy by making a GET request in the browser
GET http://webservice.buddyplatform.com/Service/v1/BuddyService.ashx?UserAccount_Profile_Create&BuddyApplicationName=EII_Application&BuddyApplicationPassword=2D5A783F-1CA2-4464-8EF0-4C0AB5279410&NewUserName=BuddyTester1234&UserSuppliedPassword=testerpw3&NewUserGender=male&UserAge=13&NewUserEmail=tester2@test.com&StatusID=1&FuzzLocationEnabled=1&CelebModeEnabled=1&ApplicationTag=&RESERVED= HTTP/1.1
Host: webservice.buddyplatform.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: Coyote-2-d063c7da=a0a1465:0
@pedroreys
pedroreys / 01_MyDslGrammar.cs
Created September 17, 2012 16:57
Using Irony with strongly typed AST nodes
public class MyDslGrammar : Grammar
{
public MyDslGrammar(): base(caseSensitive:false)
{
var binaryExpression = new NonTerminal("binaryExpression", typeof(BinaryExpressionNode));
/*...*/
}
}
@pedroreys
pedroreys / job_security.js
Created August 24, 2012 20:10
Job Security
функция f(x) {
если (x % 2 == 0) {
возврат истина;
} иначе {
возврат ложь;
}
}
для (пер i = 0; i < 10; i++) {
console.log(i, f(i));
function stringContainsAnyOfElements(string, elements){
string = string.toLowerCase();
for(var i = 0; i < elements.length; i++) {
if(string.indexOf(elements[i]) != -1) {
return true;
}
}
return false;
}
@pedroreys
pedroreys / gist:2963187
Created June 21, 2012 00:45
Alias to generate pretty git log with graph of all branches
[alias]
    lg = log --graph --pretty=format:'%C(yellow)%d%Creset %C(cyan)%h%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=short --all

This alias is going to generate an output like this:

git log example output

@pedroreys
pedroreys / NullAction.cs
Created June 20, 2012 16:35
Null Action
public class NullAction
{
public static readonly Action DoNothing = () => { };
}
//This allows you to do (callback ?? NullAction.DoNothing)() instead of (callback ?? () => { })()