Skip to content

Instantly share code, notes, and snippets.

@SamWM
SamWM / gist:261827
Created December 22, 2009 16:18
ArrayList to String
/// <summary>
/// Converts an array list to a string.
/// </summary>
/// <param name="ar">Array list</param>
/// <returns>Comma deliminated string</returns>
public static string ArrayListToString(ArrayList ar)
{
return ArrayListToString(ar, ',');
}
/// <summary>
@SamWM
SamWM / gist:261828
Created December 22, 2009 16:20
TruncatedHyperLink
/// <summary>
/// Create a hyperlink that is truncated if the text is too long
/// </summary>
/// <param name="url">Page to link to</param>
/// <param name="text">Text to show</param>
/// <param name="length">Truncate text at this length</param>
/// <returns>An anchor, truncated if appropriate</returns>
public static string TruncatedHyperLink(object url, object text, int length)
{
if (url == DBNull.Value || text == DBNull.Value) return String.Empty;
@SamWM
SamWM / gist:261830
Created December 22, 2009 16:23
String Encoding
public static string UrlEncode(object input)
{
string output = string.Empty;
if (input != DBNull.Value)
{
output = HttpUtility.UrlEncode(input.ToString());
}
return output;
}
@SamWM
SamWM / DateManipulation.cs
Last active February 17, 2016 10:42
Date Manipulation
/// <summary>
/// Go to the specified week in a given year
/// </summary>
/// <param name="year">Which year</param>
/// <param name="week">Which week in year</param>
/// <returns>Date the week falls on</returns>
public static DateTime GoToWeek(int year, int week)
{
// use the current culture
System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
@SamWM
SamWM / FormatFileSize.cs
Created December 22, 2009 16:27
FormatFileSize
private string FormatFileSize(long size)
{
return FormatFileSize((double)size);
}
private string FormatFileSize(double size)
{
string output = string.Empty;
string append = string.Empty;
string format = string.Empty;
if (size < 1000)
public static string ExtensionFromContentType(string contenttype)
{
string output = ".jpg";
switch (contenttype)
{
case "image/gif":
output = ".gif";
break;
case "image/png":
output = ".png";
@SamWM
SamWM / fastcgiphp.cmd
Created December 30, 2009 13:26
FastCGI in IIS
rem download fastcgi from http://www.iis.net/expand/FastCGI
cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" ^
-extension:php -path:"C:\PHP\php-cgi.exe"
@SamWM
SamWM / gist:266169
Created December 30, 2009 16:43
jQuery UI Dialog iframe
$("a.dialog").click(
function(e) {
e.preventDefault();
var title = this.title;
if (!title.length) title = $(this).text();
// create a dialog box and set the iframe to the linked page
var dialog = $("<div><iframe /></div>")
.find("iframe").attr({ "frameBorder": 0, "width": "100%", "height": "100%", "scrolling": "auto", "src": this.href }).end()
.dialog(
{
@SamWM
SamWM / gist:266176
Created December 30, 2009 16:49
jQuery UI Image Dialog (to replace thickbox)
$("a.thickbox").click(
function(e) {
e.preventDefault();
var link = this;
var $loading = $("<div></div>").dialog({ title: "Loading..." });
$("<img>").attr({ "src": this.href }).css({ "padding": 0 }).load(
function() {
$loading.dialog("destroy").remove();
var maxWidth = $(window).width() - 20;
var maxHeight = $(window).height() - 20;
@SamWM
SamWM / html5.html
Created January 5, 2010 10:00
jQuery & HTML5
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Site | Page 1</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$( function() {
$("body").append("<p>Hello from jQuery!</p>");
});