Skip to content

Instantly share code, notes, and snippets.

View jamesmanning's full-sized avatar

James Manning jamesmanning

View GitHub Profile
@jamesmanning
jamesmanning / weird.rb
Created April 25, 2012 05:14
weird array slice behavior
def test_slicing_arrays_is_weird
array = [:peanut, :butter, :and, :jelly]
assert_equal :peanut, array[0]
assert_equal :butter, array[1]
assert_equal :and, array[2]
assert_equal :jelly, array[3]
# this confirms that 4 is an invalid index into the array
assert_equal nil, array[4]
@jamesmanning
jamesmanning / heredoc.rb
Created April 25, 2012 05:25
ruby flexible quoting adds initial newline that here-doc does not
def test_old_style_here_doc
here_doc_style = <<WHEE
foo
bar
WHEE
flexible_quote_style = %{
foo
bar
}
USE [master]
GO
CREATE DATABASE [testing]
GO
USE [testing]
GO
CREATE TABLE [dbo].[Items](
@jamesmanning
jamesmanning / Program.cs
Created May 6, 2012 12:32
simple TCP client and server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
void Main()
{
var instances = new AbstractBase[]
{
new RegularTaskApproach(),
new AsyncAwaitApproach(),
new RegularTaskDerivedFromAsyncAwaitApproach(),
new RegularTaskUsingBaseAsyncAwaitApproach(),
};
@jamesmanning
jamesmanning / CallPremailerApi.cs
Created June 5, 2012 15:42
linqpad script (needs reference to Newtonsoft.Json) for calling premailer API - see http://premailer.dialect.ca/api
void Main()
{
var webClient = new WebClient();
var requestParameters = new NameValueCollection()
{
{ "url", "http://www.hondaelcerritonews.com/news/2012/MayNewsletter/?view=Email" },
{ "preserve_styles", "false" },
{ "remove_ids", "true" },
{ "remove_classes", "true" },
@jamesmanning
jamesmanning / RemoveDeadTracks.ps1
Created June 9, 2012 17:03
PowerShell script to remove dead entries from the iTunes library
# get reference to the running iTunes
$itunes = New-Object -ComObject iTunes.application
# get all tracks in the entire library
$allTracks = $itunes.LibraryPlaylist.Tracks
# find the entries that are no longer on disk
# NOTE: the API returns the location as null for those, so we check for
# that instead of doing our own filtering based on test-path or similar
$deadEntries = $allTracks | ?{ $_.Location -eq $null }
@jamesmanning
jamesmanning / sp_generate_inserts2.sql
Created June 22, 2012 18:14
slightly better version of sp_generate_inserts
SET NOCOUNT ON
GO
PRINT 'Using Master database'
USE master
GO
PRINT 'Checking for the existence of this procedure'
IF (SELECT OBJECT_ID('sp_generate_inserts','P')) IS NOT NULL --means, the procedure already exists
BEGIN
@jamesmanning
jamesmanning / GetDatabaseInfo.linq.cs
Last active January 15, 2024 03:54
LINQPad script to get basic schema information about the currently selected database (assumes LINQPad's default data context creation method)
void Main()
{
var databaseInfo = GetDatabaseInfo(this);
databaseInfo.Dump();
}
// Define other methods and classes here
public class DatabaseInfo
{
public Type DataContextType { get; set; }
@jamesmanning
jamesmanning / GenerateAlterColumnNotNullStatements.linq.cs
Created December 27, 2012 21:23
LINQPad script to generate the set of possible 'alter table alter column not null' statements for the nullable columns in a database
void Main()
{
var databaseInfo = GetDatabaseInfo(this);
// databaseInfo.Dump();
foreach (var table in databaseInfo.Tables)
{
var nullableColumns =
from c in table.Columns
where c.DatabaseType.EndsWith(" NOT NULL") == false