Skip to content

Instantly share code, notes, and snippets.

//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//
@jarrettmeyer
jarrettmeyer / ObjectToDictionaryHelper.cs
Created January 27, 2011 15:53
C# convert an object to a dictionary of its properties
public static class ObjectToDictionaryHelper
{
public static IDictionary<string, object> ToDictionary(this object source)
{
return source.ToDictionary<object>();
}
public static IDictionary<string, T> ToDictionary<T>(this object source)
{
if (source == null)
@rdingwall
rdingwall / DynamicJsonDeserializer.cs
Created February 22, 2012 12:22
RestSharp deserialize JSON to dynamic
// ReSharper disable CheckNamespace
namespace RestSharp.Deserializers
// ReSharper restore CheckNamespace
{
public class DynamicJsonDeserializer : IDeserializer
{
public string RootElement { get; set; }
public string Namespace { get; set; }
public string DateFormat { get; set; }
@codysoyland
codysoyland / virtualenv-auto-activate.sh
Created March 25, 2012 18:34
virtualenv-auto-activate
#!/bin/bash
# virtualenv-auto-activate.sh
#
# Installation:
# Add this line to your .bashrc or .bash-profile:
#
# source /path/to/virtualenv-auto-activate.sh
#
# Go to your project folder, run "virtualenv .venv", so your project folder
# has a .venv folder at the top level, next to your version control directory.
@jeffwilcox
jeffwilcox / gist:2432351
Created April 20, 2012 22:33
WinRT IsInstanceOfType, IsAssignableFrom
/// <summary>
/// Determines whether the specified object is an instance of the current Type.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="o">The object to compare with the current type.</param>
/// <returns>true if the current Type is in the inheritance hierarchy of the
/// object represented by o, or if the current Type is an interface that o
/// supports. false if neither of these conditions is the case, or if o is
/// null, or if the current Type is an open generic type (that is,
@jinze
jinze / forever-initd-example.sh
Created September 19, 2012 09:50
forever init.d example
#!/bin/bash
#
# initd-example Node init.d
#
# chkconfig: 345 80 20
# description: Node init.d example
# processname: node
# pidfile: /var/run/initd-example.pid
# logfile: /var/log/initd-example.log
#
@igniteflow
igniteflow / gist:4088322
Created November 16, 2012 15:41
Clear the SUDS WSDL cache
"""
SUDS caches WSDL files by default. This command will clear the cache.
"""
from openkm import client
client = client.Client(url)
client.options.cache.clear()
@naga41
naga41 / gist:4254447
Created December 10, 2012 23:49
Jenkins jnlp slave init script
#!/bin/sh
#
# jenkins-slave: Launch a Jenkins BuildSlave instance on this node
#
# chkconfig: - 99 01
# description: Enable this node to fulfill build jobs
#
# Source function library.
. /etc/rc.d/init.d/functions
// Yields the approximate result of a division by 1000.
// NOTE: Can only be used for numbers less than 140,737,488,290
unsigned long quickDiv1000(unsigned long num)
{
unsigned long result;
result = num * 65 + (num >> 2) + (num >> 5) + (num >> 8)+ (num >> 11) + 32768;
return (result >> 16);
}
@timd
timd / gist:4953071
Created February 14, 2013 14:11
Example of Kiwi test involving Magical Record managed objects and view controllers
#import "Kiwi.h"
#import "MyController.h"
#import "Record.h"
#import "MyModel.h"
// Category on class under test to expose private properties / methods
@interface MyController(MyTest)
@property (nonatomic, strong) NSDictionary *aDictionary;
@property (weak, nonatomic) IBOutlet UIButton *aButton;