Skip to content

Instantly share code, notes, and snippets.

View trcio's full-sized avatar

patricio trcio

  • Texas
  • 21:18 (UTC -05:00)
View GitHub Profile
@trcio
trcio / JsonUtil.cs
Last active August 28, 2016 23:33
An easy to use JSON serializer/deserializer. Requires the assembly reference of 'System.Runtime.Serialization'.
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
public static class JsonUtil
{
/// <summary>
/// Serializes an object to the respectable JSON string.
/// </summary>
public static string Serialize<T>(T o)
@trcio
trcio / Instasign.cs
Last active August 29, 2015 14:02
Instasign wrapper (my product)
using System;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Text;
using System.Net;
using System.IO;
using Instasign.Models;
namespace Instasign
@trcio
trcio / UnixTime.cs
Last active August 29, 2015 14:02
Unix Timestamp for C#
public static class UnixTime
{
public static int Get()
{
return (int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
}
public static DateTime ToDateTime(int timestamp)
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
@trcio
trcio / IntervalTimer.cs
Last active August 29, 2015 14:02
An Interval Timer for C#. Specify the minimum and maximum time between intervals, and let the timer do the rest!
using System;
using System.Threading;
public sealed class IntervalTimer
{
private Timer timer;
private Random rand;
private int min, max;
public event Action Interval;
@trcio
trcio / Callbackr.cs
Last active August 29, 2015 14:02
Callbackr: Easy callback class, for all your callback needs!
public static class Callbackr
{
private static Dictionary<object, Action> callbacks = new Dictionary<object, Action>();
/// <summary>
/// Adds the specified callback with the specified identifier.
/// </summary>
/// <param name="token">The callbacks specified identifier.</param>
/// <param name="callback">The callback to be added.</param>
public static void Add(object token, Action callback)
@trcio
trcio / SpeedyClient.cs
Created July 27, 2014 21:05
Adds speed/time remaining to the ProgressChangedEventArgs of a webclient
using System;
using System.Net;
using System.ComponentModel;
using System.Diagnostics;
namespace SpeedClient
{
public delegate void SpeedyDownloadProgressChangedEventHandler(SpeedyDownloadProgressChangedEventArgs e);
public delegate void SpeedyUploadProgressChangedEventHandler(SpeedyUploadProgressChangedEventArgs e);
@trcio
trcio / EmailAddress.cs
Last active August 29, 2015 14:04
Provides and Electronic Mail (Email) address.
using System.Text.RegularExpressions;
namespace System.Net.Mail
{
/// <summary>
/// Provides an Electronic Mail (Email) address.
/// </summary>
public sealed class EmailAddress
{
private const string EMAIL_PATTERN = @"([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*)@((?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\.+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)";
@trcio
trcio / Csrfer.php
Last active August 29, 2015 14:05
An easy way to implement CSRF protection into your web forms.
<?PHP
class Csrfer {
const SESSION_NAME = 'csrfer_name';
const SESSION_VALUE = 'csrfer_value';
const TOKEN_FORMAT = '<input type=\'hidden\' name=\'%s\' value=\'%s\'>';
const TOKEN_LENGTH = 128;
Imports System.Runtime.Serialization.Json
Imports System.IO
Imports System.Text
Public Class JsonUtil
''' <summary>
''' Serializes an object to the respectable JSON string.
''' </summary>
Public Shared Function Serialize(Of T)(o As T) As String
Dim s = New DataContractJsonSerializer(GetType(T))
@trcio
trcio / PCompiler.cs
Created August 17, 2014 06:54
Small, easy CodeDom wrapper
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Resources;
using System.Text;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
namespace PCompile
{