Skip to content

Instantly share code, notes, and snippets.

View jjokela's full-sized avatar

Jarmo Jokela jjokela

View GitHub Profile
@jjokela
jjokela / gist:c4759889f84d98003242
Last active August 29, 2015 14:05
SQL Joins explained
-- Table contents
-- Customers
-- CustomerID CustomerName Country
-- 1 Jarmo Suomi
-- 2 Risto Ruotsi
-- 3 Erno Englanti
-- 4 Testeri Testimaa
-- Orders
@jjokela
jjokela / generics.cs
Created August 10, 2014 20:09
C# Generics sample
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleGenericsTest
{
/// <summary>
/// Generic registration class
/// </summary>
@jjokela
jjokela / delegate.cs
Created August 11, 2014 07:26
C# Delegates
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFormsDelegateTest
@jjokela
jjokela / lifecycle.cs
Created August 11, 2014 08:02
WinForms Lifecycle Events
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFormsLifecycleEvents
@jjokela
jjokela / SingleInstance.cs
Created August 11, 2014 11:05
Winform single instance
using Microsoft.VisualBasic.ApplicationServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WinFormsSingleInstance
{
static class Program
{
@jjokela
jjokela / CoAndContraVariance.cs
Created August 13, 2014 11:17
Covariance and Contravariance
// Airplane = base class
// F16 = derived class
// covariance: can use MORE spesific type than originally specified
IEnumerable<F16> f16s = new List<F16>();
IEnumerable<Airplane> covariance = f16s;
// contravariance: can use LESS specific type than originally specified
Action<Airplane> airplanes = (target) => { Console.WriteLine(target.GetType().Name); };
Action<F16> contravariance = airplanes;
@jjokela
jjokela / WidgetFactory.cs
Created September 4, 2014 08:16
Factory: load types by using reflection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace WidgetApp
{
/// <summary>
/// Simple factory that creates a widget based on its name
var obj = {};
var func = function(){ return 'moro' };
var func2 = function(){ return 'no terve terve'};
console.log(func());
obj.prop = func;
@jjokela
jjokela / hackerrank.cs
Last active March 4, 2018 15:44
Utility code for Hackerrank exercises
// char array containing lower-case letters from a..z
var letters = new char[] {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
// int to binary string with leading zeros
Convert.ToString(3, 2).PadLeft(4, '0'); // 0011
Convert.ToString(3, 2).PadLeft(8, '0'); // 00000011
// binary to int
int output = Convert.ToInt32(input, 2);