Skip to content

Instantly share code, notes, and snippets.

View g-un--'s full-sized avatar

Gino Ungureanu g-un--

View GitHub Profile
var pipeline = Pipeline
.Empty<int>()
.Next(next => value => { Console.WriteLine(value); next(value); })
.Next(next => value => { Console.WriteLine(value+1); next(value); })
.Build();
pipeline(1);
public static class Pipeline
{
@g-un--
g-un-- / Program.cs
Last active January 19, 2022 08:37
Y Combinator C#
namespace Application
{
public static class YComb<T,R>
{
delegate Func<T,R> Y(Lambda x);
delegate Func<T, R> Rec(Rec rec);
public delegate Func<T,R> Lambda(Func<T,R> rec);
@g-un--
g-un-- / TailCall.cs
Created October 15, 2018 07:56
Tail Recursive Call
using System;
namespace TailRecursive
{
class Program
{
static void Main(string[] args)
{
var f = SyncTailCall<int,int>
.As((me, item) =>
@g-un--
g-un-- / Program.cs
Created October 8, 2017 13:16
YComb C#
using System;
namespace RecAgain
{
class Program
{
static void Main(string[] args)
{
var factorial = YComb.Fix<int, int>(f => val => val > 1 ? val * f(val - 1) : 1);
var factorial2 = YComb.FixStack<int, int>(f => (acc, val) => val > 1 ? f(acc * val, val - 1) : acc, 1);
@g-un--
g-un-- / geo-sql-to-mongo.js
Last active August 29, 2015 14:10
Import mssql geometries into mongodb as geojson
//npm install mongodb
//npm install edge
//npm install edge-sql
//npm install rx
//npm install wellknown
//Set the connection string as an environment variable (your connection string may be different):
//with powershell: $env:EDGE_SQL_CONNECTION_STRING="Data Source=localhost;Initial Catalog=Db;Integrated Security=True"
//and finally
//node geo-sql-to-mongo.js
@g-un--
g-un-- / y-combinator.fsx
Last active August 29, 2015 14:10
f# fsharp fibonacci with y combinator
open System.Collections.Generic
printfn "\nfib recursive"
let rec fib n = if n > 1 then fib(n-1) + fib(n-2) else n
[1..10] |> Seq.iter(fun n ->
printfn "fib(%d)= %d" n (fib(n)))
printfn "\nlambda fib -> rec y comb"
let lambdafib fib n = if n > 1 then fib(n-1) + fib(n-2) else n
@g-un--
g-un-- / repo.fs
Created May 15, 2014 16:15 — forked from HarryR/repo.fs
(* Copyright © 2014 G Roberts. All Rights Reserved *)
namespace MiniForum.Model
open System
open System.Threading.Tasks
open MiniForum
open MiniForum.Model
open Fredis
1. FOR XML RAW('Customer'), ROOT('Customers')
-> rows are node xml elements with <Customer ColumnName="ColumnValue" />
-> columns are attributes
-> root is customers
2. FOR XML ROW('Customer'), ROOT('Customers'), ELEMENTS
-> columns are xml elements
3. FOR XML ROW('Customer'), ROOT('Customers'), ELEMENTS XSINIL
WITH RunningTotals AS
(
SELECT custid, orderid, orderdate, val,
SUM(val) OVER(PARTITION BY custid
ORDER BY orderdate, orderid
ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW) AS runningtotal
FROM Sales.OrderValues
)
SELECT *
SELECT orderid, orderdate, custid, empid
FROM Sales.Orders
ORDER BY orderdate DESC, orderid DESC
OFFSET 50 ROWS FETCH NEXT 25 ROWS ONLY;