Skip to content

Instantly share code, notes, and snippets.

@Sheeo
Sheeo / gist:732149
Created December 7, 2010 18:01
Awesomeness
# Ruby-RSpec klasse brugt til at beskrive MultiSet-java klassen med
#
# For at køre:
# make spec
#
# Kræver:
# jruby (http://jruby.org)
# rspec (gem install rspec)
#
<% content_for :nav do %>
<ul>
<%
items = ["Forside", "Rediger quiz", "Kategorier", "Spilrunder"]
descriptions = ["Gå til forsiden", "Rediger en quiz", "Opsæt kategorier", "Vælg spilrunder"]
items.each_index do |key|
item = items[key]
item_description = descriptions[key]
if !is_active_page?(:key)
@Sheeo
Sheeo / gist:1104920
Created July 25, 2011 19:14
Not the way to add rows to a table
Public Shared Function GenerateNewUniqueID() As String
Dim returnString As String = Guid.NewGuid.ToString()
Dim unique As Boolean = False
Using conn As New SqlConnection(My.Settings.onlinePDFConnectionString)
conn.Open()
Dim commString As String = "SELECT Count(*) FROM Books WHERE UniqueID = '{0}%'"
@Sheeo
Sheeo / gist:1261718
Created October 4, 2011 14:02
ddb generation
Pruning tables.
Executing: DELETE FROM Branches;
Nil result
Executing: DELETE FROM Accounts;
Nil result
Executing: DELETE FROM Customers;
Nil result
Executing: DELETE FROM Transactions;
Nil result
Inserting branch
@Sheeo
Sheeo / gist:1337590
Created November 3, 2011 19:50
Generic awesomeness in C#
public void Add<TEntity>(TEntity t) where TEntity : class
{
var properties = (from p in GetType().GetProperties()
select p.GetGetMethod(true));
var genericProperties = (from property in GetType().GetProperties()
let returntype = property.GetGetMethod(true).ReturnType
where returntype.IsGenericType
where returntype.GetGenericArguments().Length == 1
let argumenttype = returntype.GetGenericArguments().First()
where argumenttype == typeof (TEntity)
mat
|> Array.iteri (fun m i -> Array.iter (fun n -> printfn "%d" mat.[m].[n]) mat.[m])
// vs
mat
|> Array.iteri (fun m i -> mat.[m]
|> (fun n -> printfn "%d" mat.[m].[n]))
// vs
let printMatrixRec2((mat : int[][])) =
let rec iterate r c =
match r, c with
| m,n when n = mat.[m].Length-1 && m = mat.Length-1 -> printf " %d" mat.[m].[n]; () // Base case, last entry: Stop recursion when r,c are at bounds of Mat int[][] array
| m,n when n = mat.[m].Length-1 -> printf " %d\n" mat.[m].[n]; iterate (m+1) 0 // Special case: last column of row m, print special and iterate next row
| m,n when n=0 -> printf "%d " mat.[m].[n]; iterate m (n+1) // Special case: first column of m
| m,n -> printf " %d " mat.[m].[n]; iterate m (n+1) // Normal case: entry m,n
iterate 0 0
using System;
using System.Security.Permissions;
using System.Threading;
class ThreadInterrupt
{
static void Main()
{
StayAwake stayAwake = new StayAwake();
Thread newThread =
@Sheeo
Sheeo / gist:3371002
Created August 16, 2012 15:23
Sql Server SSI
public override void CreateNewOutputRows()
{
string strCurrency;
string flRate;
XmlDocument xm = new XmlDocument();
xm.Load(Variables.ECBRL.ToString());
XmlNodeList xnode = xm.GetElementsByTagName("Cube");
DateTime date = DateTime.Parse(xm.GetAttribute("time"));
(** Additions to weedingast.ml, bottom **)
let type_decl_members td = match td.type_decl with
| Class d -> d.class_members
| Interface i -> i.interface_members
let decl_name decl = match decl.decl with
| Field f -> f.field_name.Ast.identifier
| Method m -> m.method_name.Ast.identifier
| Constructor c -> c.constructor_name.Ast.identifier