Skip to content

Instantly share code, notes, and snippets.

View rod-dot-codes's full-sized avatar

Rodney Hawkins rod-dot-codes

View GitHub Profile
@rod-dot-codes
rod-dot-codes / MobileController.cs
Created July 31, 2013 13:18
I found this lovely piece of code that really makes your DateTime's look extremely professional. I'm warning you, it does.
static string GetPrettyDate(DateTime d)
{
// 1.
// Get time span elapsed since the date.
TimeSpan s = DateTime.Now.Subtract(d);
// 2.
// Get total number of days elapsed.
int dayDiff = (int)s.TotalDays;
@rod-dot-codes
rod-dot-codes / Program.cs
Created July 31, 2013 13:23
Create an embedded certificate and access it with the following awesome code I found online.
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("<PackageName>.<Filename>");
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
string certPassword = "";
var cert = new X509Certificate2(bytes, certPassword);
@rod-dot-codes
rod-dot-codes / Program.cs
Last active December 20, 2015 11:19
Writes a datatable to a .csv file. Efficient, easy and works like a charm.
static void WriteDataTableToCSV(DataTable dt, string fileName, char separator)
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName);
foreach (DataColumn column in dt.Columns)
{
sw.Write(column.ColumnName);
sw.Write(separator);
}
sw.WriteLine();
@rod-dot-codes
rod-dot-codes / gist:6122339
Created July 31, 2013 14:15
A great redirection to mobile site code I found online at some super awesome site, forgot the url though, posting here to remember it
string u = Request.ServerVariables["HTTP_USER_AGENT"];
Regex b = new Regex(@"(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Regex v = new Regex(@"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp
@rod-dot-codes
rod-dot-codes / dbo.GetDaysInYear.sql
Created September 6, 2013 06:00
Get the number of days in a year in SQL. So instead of using 365.25 for financial calculations, you can use this. Heavily based on http://www.sql-server-helper.com/functions/get-days-in-year.aspx, I only added the is null date option.
CREATE FUNCTION [dbo].[ufn_GetDaysInYear] ( @pDate DATETIME )
RETURNS INT
AS
BEGIN
if (@pDate is null)
SET @pDate = GETDATE()
DECLARE @IsLeapYear BIT
SET @IsLeapYear = 0
@rod-dot-codes
rod-dot-codes / fabfile.py
Created October 17, 2013 14:01
A simple Fabfile which can be used to install Salt. Version 2 of this file, will use a Jinja configuration template for both master and minion and simply overwrite the files on each deployment. Example deployment: fab install_salt:True
#!/usr/bin/python
from __future__ import with_statement
from fabric.api import local, settings, abort, run, cd,env,sudo
from fabric.contrib.console import confirm
env.hosts = ['<server>']
env.user = '<user>'
salt_interface = '0.0.0.0' #Bind to all
salt_master = 'salt.<domain>' #Set up your subdomain salt, I like this version.
@rod-dot-codes
rod-dot-codes / LinqPad-QueueMe.cs
Created October 31, 2013 09:45
Read the last message of a C# Queue
MessageQueue queue = new MessageQueue("FormatName:DIRECT=OS:<queue_address>")
{
MessageReadPropertyFilter = new MessagePropertyFilter
{
ArrivedTime = true,
Body = true
}
};
Console.WriteLine(queue.CanRead.ToString());
Console.WriteLine(queue.CanWrite.ToString());
@rod-dot-codes
rod-dot-codes / 0_reuse_code.js
Created November 29, 2013 08:29
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rod-dot-codes
rod-dot-codes / Cuda.cu
Created March 24, 2014 18:32
The CUDA Code for the Game of Life project.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//Dependent on your Nvidia graphics card. Mine had a BLOCK_SIZE of 32.
#define BLOCK_SIZE 32
#define TILE_SIZE 32
//Rounds the value up to a multiple of BLOCK_SIZE.
//Usage found down south: dim3 dimGridProj(iDivUp(rowCount,BLOCK_SIZE), iDivUp(columnCount,BLOCK_SIZE));
@rod-dot-codes
rod-dot-codes / PutYourCodeHere.cs
Created March 24, 2014 18:33
The NML Code Challenge Runner in C# for passing to the CUDA kernel.dll
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;