Skip to content

Instantly share code, notes, and snippets.

@SamWM
SamWM / FinancialMonthYear.cs
Last active January 3, 2016 21:49
Return the input DateTime values current financial month, year or both
public static int FinancialMonth(DateTime date)
{
int month = date.Month - 3;
if (date.Month <= 3)
{
month = month + 12;
}
return month;
}
$.fn.intcheck = function () {
return this.bind("keyup", function () {
this.value = this.value.replace(/[^0-9]/g, '');
if (isNaN(this.value)) {
while (isNaN(this.value)) {
var len = this.value.length;
if (len < 1) break;
this.value = this.value.substring(0, len - 1);
}
}
@SamWM
SamWM / readoutput.cs
Created December 4, 2012 17:51
Launch Other Processes (C#)
void Main()
{
Process p = new Process();
p.EnableRaisingEvents = true;
ProcessStartInfo pi = new ProcessStartInfo { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, FileName = "cmd.exe", Arguments = "/c dir /w" };
p.Exited += delegate {
Console.WriteLine("--ExitCode--" + Environment.NewLine + p.ExitCode);
Console.WriteLine("--StandardOutput--" + Environment.NewLine + p.StandardOutput.ReadToEnd());
Console.WriteLine("--StandardError--" + Environment.NewLine + p.StandardError.ReadToEnd());
};
@SamWM
SamWM / gist:3742267
Created September 18, 2012 09:38
ASP.NET MVC: get action / controller name
string controllerName = ViewContext.RouteData.GetRequiredString("controller");
string actionName = ViewContext.RouteData.GetRequiredString("action");
@SamWM
SamWM / recurse.cs
Created August 16, 2012 11:33
Directory Recursion (using memoization)
void Main()
{
Queue<string> directories = new Queue<string>(Directory.GetDirectories(@"C:\Windows\system32\"));
do
{
string dir = directories.Dequeue();
Console.WriteLine("Directory: " + dir);
try
{
string[] subdirs = Directory.GetDirectories(dir);
@SamWM
SamWM / trafficlight.html
Created July 30, 2012 16:27
Alternating background colours for table cells, returning to start when last one is reached (using jQuery)
<table style="padding: 3px; background: #111; border-radius: 8px" cellspacing="4">
<tr>
<td class="light" width="50" height="50" data-bg="#f8696b" style="background: #fff; border-radius: 25px;">
</td>
</tr>
<tr>
<td class="light" width="50" height="50" data-bg="#f9e983" style="background: #fff; border-radius: 25px;">
</td>
</tr>
<tr>
@SamWM
SamWM / ageranges.cs
Created July 5, 2012 09:00
List of age ranges
class MyClass
{
public static List<string> AgeRanges
{
get
{
int start = 10;
int end = 59;
int step = 5;
int i = start;
@SamWM
SamWM / web.config
Created June 20, 2012 09:57
Url Rewriting IIS7+ (Windows 2008)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
@SamWM
SamWM / layeredblockanimation.html
Created June 1, 2012 09:50
jQuery Layered Block Animation
<!DOCTYPE html>
<html>
<head>
<style>
#blocks
{
position: relative;
}
@SamWM
SamWM / formatnodecimal.cs
Created May 14, 2012 12:03
Format Currency - no decimals
System.Globalization.NumberFormatInfo nfi = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.LCID).NumberFormat;
nfi.CurrencyDecimalDigits = 0;
var formatted = string.Format(nfi, "{0:C}", 120);