Skip to content

Instantly share code, notes, and snippets.

View zckkte's full-sized avatar

Zack A. Kite zckkte

  • Copenhagen, Denmark
View GitHub Profile
@zckkte
zckkte / merge_sort.rb
Created June 19, 2017 10:40
Merge-sort implementation in Ruby
#!/usr/bin/env ruby
def main()
n = ARGV.first.to_i
array = []
for i in 1..n
array << rand(1..n)
end
start_t = Time.now
merge_sort(array)
@zckkte
zckkte / iamg.rb
Last active June 19, 2017 10:42
A simple script which generates a static html page containing all images under the specified directory
require 'launchy'
EXTENSIONS = /^.*\.(jpg|png|gif)$/i
STYLES = %q(
#images {
line-height: 0;
-webkit-column-count: 5;
-webkit-column-gap: 5px;
-moz-column-count: 5;
@zckkte
zckkte / primes.hs
Created June 20, 2017 11:37
A simple prime sieve in Haskell
isPrime :: Integer -> Bool
isPrime x = all (==True) [ x `mod` y /= 0 | y <- [2..x-1]]
primes = [ x | x <- [1..], isPrime x ]
@zckkte
zckkte / Lambda.cs
Last active June 28, 2017 10:48
Curryable lambda function
/*
* https://blogs.msdn.microsoft.com/sriram/2005/08/07/functional-programming-in-c-currying/
*/
public class Lambda
{
public delegate T Function<T, U>(params U[] args);
public static Function<K, J> Curry<K, J>(Function<K, J> func, params J[] curriedArgs)
{
@zckkte
zckkte / knn.rb
Last active July 9, 2017 05:02
k-nearest neighbours algorithm implemented in Ruby
require 'csv'
DEFAULT_SPLIT_RATIO = 0.66
def main
fileName, k, userSplit = ARGV
splitRatio = userSplit.nil? ? DEFAULT_SPLIT_RATIO : userSplit.to_f
trainSet, testSet = loadData(fileName, splitRatio)
predictions = Array.new
testSet.each do |testInstance|
@zckkte
zckkte / ControllerExtensions.cs
Last active July 15, 2017 05:13
Render partial view to string given a POCO model
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace ControllerInfrastructure
{
@zckkte
zckkte / register_standup_alias.sh
Last active July 15, 2017 09:48 — forked from peabnuts123/register_standup_alias.sh
Git alias to show what you've done in the last day
git config --global alias.standup 'log --pretty="%C(red)%an%Creset %C(green)%ad%Creset | %s%C(yellow)%d%Creset" --since=yesterday --all --reverse --date="format:%d/%m %a %T" --author="Your Name"'
-- ===============================================
-- Create SQL Login template for Windows Azure SQL Database
-- reference: https://azure.microsoft.com/en-us/blog/adding-users-to-your-sql-azure-database/
-- ===============================================
-- The SQL Server administrative login needs to be conected to the master database to execute CREATE LOGIN command
USE [master]
GO
-- Create a login that can connect to the SQL server
public static class YCombinator<T> {
delegate Func<T, T> Recursive(Recursive recursive);
public static Func<Func<Func<T, T>, Func<T, T>>, Func<T, T>> Fix =
f => ((Recursive)(g => (f(x => g(g)(x))))) ((Recursive)(g => f(x => g(g)(x))));
}
using System;
namespace Nulls
{
public struct Maybe<T> : IEquatable<Maybe<T>>
where T : class
{
private readonly T _value;
public T Value
{