Skip to content

Instantly share code, notes, and snippets.

@SamWM
SamWM / daymessage.php
Created September 8, 2011 12:45
Different message depending on day
$today = time();
// days start at 0 (Sunday) to 6 (Saturday)
$messages = array(
0 => "Sorry we are closed",
1 => "We are open between <strong>8am - 6.30pm</strong>",
2 => "We are open between <strong>8am - 8pm</strong>",
3 => "We are open between <strong>8am - 6.30pm</strong>",
4 => "We are open between <strong>8am - 6.30pm</strong>",
5 => "We are open between <strong>8am - 6.30pm</strong>",
6 => "Sorry we are closed"
@SamWM
SamWM / horizontal_menus.html
Created August 25, 2011 09:39
Horizontal JavaScript (jQuery) Menus
<!DOCTYPE html>
<html>
<head>
<title>Horizontal Menus</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<style type="text/css" media="screen">
#quicklinks h1
{
color: #FF0090;
@SamWM
SamWM / FileSize.cs
Created August 11, 2011 17:11
Display file size as b, Kb, Mb etc
protected string FileSize(long size)
{
string output = string.Empty;
double multiply = Math.Pow(10, 2);
string[] units = new string[] { "b", "Kb", "Mb", "Gb", "Tb", "Pb" };
int exponent = (int)Math.Floor(Math.Log(size) / Math.Log(1024));
output = (Math.Round(size / Math.Pow(1024, exponent) * multiply) / multiply) + units[exponent];
@SamWM
SamWM / linq2sqldebug.cs
Created June 27, 2011 12:00
Linq2SQL - get generated SQL
// using System.IO;
// using System.Text;
MyDBContext db = new MyDBContext();
StringWriter w = new StringWriter();
db.Log = w;
... do LINQ2SQL stuff
string SQL = w.GetStringBuilder().ToString();
@SamWM
SamWM / epplusworksheet.cs
Created June 17, 2011 16:50
EPPlus Worksheet Formatting (using http://epplus.codeplex.com/)
using System.Text;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
using System.Drawing;
using System.Data;
public partial class Sample: Page
{
protected void GenerateSpreadsheet(object sender, EventArgs e)
@SamWM
SamWM / cssmenu.html
Created April 4, 2011 15:41
CSS Submenu Relative Positioned Container
<!DOCTYPE html>
<html>
<head>
<title>CSS Submenu Relative Positioned Container</title>
<style type="text/css">
#nav, #other { position: relative; }
#nav { height: 50px; background: #eee;}
#menu { position: absolute; right: 240px; top: 10px}
#menu ul { list-style-type: none; margin: 0; padding: 0; }
#menu ul li { float: left; position: relative; height: 28px; line-height: 28px; }
@SamWM
SamWM / DeleteOldFile.vbs
Created February 3, 2011 11:32
Delete old files in a folder and its sub folders (use with caution as you may end up deleting more than you intend)
Dim oFSO, oFolder, oFiles, oSubFolders
Dim oFile
Dim days
days = 200
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("path to folder")
ParseFolder oFolder
@SamWM
SamWM / FileExtension.vbs
Created February 3, 2011 11:29
Get the file extension of a File object as returned by File System Object
Function FileExtension(oFile)
Dim lastDot
lastDot = InStrRev(CStr(oFile.Name), ".")
If lastDot = 0 Or lastDot = Null Then
FileExtension = ""
Else
FileExtension = Mid(CStr(oFile.Name), lastDot + 1)
End If
@SamWM
SamWM / build_time_options.php
Created July 20, 2010 09:46
Build time select, with dropdowns for hour and minute
<?php
function pad_number(&$item, $key, $pad = 2)
{
$item = sprintf('%0'.$pad.'d', $item);
}
function build_time_options($hours, $minutes, $time)
{
// pad hours and minutes with 0
@SamWM
SamWM / CSVExtensions.cs
Created June 14, 2010 16:23
Extension Methods for Generating CSV strings from objects (C# 3.0)
using System;
public static class CSVExtensions
{
public static string ToCSV(this DataTable dt)
{
string output = string.Empty;
string tmp;
char[] special = new char[] { '"', '\n', '\r', ',' };
// loop through all columns