Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
hodzanassredin / HLIst.cs
Last active August 29, 2015 14:03
heterogenous list in csharp
using System;
using System.Collections.Generic;
namespace Kinded
{
class HList<TLower>
{
public virtual System.Collections.Generic.IEnumerable<TLower> All ()
@hodzanassredin
hodzanassredin / AsyncMonad.cs
Created June 24, 2014 11:31
tutorial2 finished monad transformer
using System;
using System.Threading.Tasks;
namespace GenericMonad
{
public class Async
{
Async ()
{
@hodzanassredin
hodzanassredin / AsyncM.cs
Last active September 19, 2017 17:27
monad tutorial
using System;
using System.Threading.Tasks;
using System.Net;
namespace GenericMonad
{
public interface IMonad<T, TMI>
{
IMonad<TB,TMI> Return<TB> (TB val);
@hodzanassredin
hodzanassredin / unwrap.fs
Last active August 29, 2015 14:02
unwrap seq of asyncs into async seq
let! results = todo |> Seq.map (fun (name, param, sql) -> (name, db.ExecuteAsync conn param sql))
|> Seq.fold (fun (asyncAcc:Async<seq<string*Result<int>>>) (name,asyncTask) -> async{
let! acc = asyncAcc
let! taskRes = asyncTask
return seq {yield! acc; yield (name, taskRes)}
}) (async {return Seq.empty})
@hodzanassredin
hodzanassredin / user.behaviors
Created May 27, 2014 09:02
lightTable settings for auto format on save. selection clear doesnt work
;; User behaviors
;; -----------------------------
;; Behaviors are stored as a set of diffs that are merged together
;; to create the final set of functionality that makes up Light Table. You can
;; modify these diffs to either add or subtract functionality.
;;
;; Behaviors are added to tags, objects with those tags then automatically gain
;; whatever logic the behavior imparts. To see a list of user-level behaviors,
;; start typing a word related to the functionality you want in between the square
;; brackets (e.g. "theme").
@hodzanassredin
hodzanassredin / trait.cs
Created May 26, 2014 12:51
version of previous gist to languge without generics, methods but with procedural pointers like oberon
using System;
namespace Test
{
public class TestTrait{//this class is not required but it reduces loc
public readonly Test Self;
public TestTrait (Test self){Self = self;}
}
public class A : TestTrait
@hodzanassredin
hodzanassredin / Traits.cs
Last active August 29, 2015 14:01
composition over inheritance pattern which doesn't require to define forward methods
using System;
namespace Traits
{
public interface Has<T>{T Trait {get;}}
public static class HasExt{
public static TRAIT GetTrait<TRAIT, SELF>(this SELF self) where SELF : Has<TRAIT>{
return self.Trait;
}
@hodzanassredin
hodzanassredin / dokku_clean.sh
Created May 12, 2014 08:54
clean unused docker images wen recieving Error: create: no space left on device
docker images | grep '<none>' | awk '{print $3}' | xargs docker rmi
@hodzanassredin
hodzanassredin / imagekit-watermark.py
Created April 16, 2014 14:46
simple pil(pillow) watermark with shadow processor for django-imagekit(PILKit) sample result https://pbs.twimg.com/media/BlWe6JeCAAAUxru.jpg
from PIL import Image
from PIL import ImageFilter
from PIL import ImageOps
from PIL import ImageDraw
from PIL import ImageFont
from PIL import ImageColor
from django.conf import settings
class TextWatermark(object):
def __init__(self, text):
@hodzanassredin
hodzanassredin / vk-api.fs
Created December 27, 2013 11:23
vk api type providers way
type getter = string->seq<string * string> -> Async<string>
type ResponseWallGet = JsonProvider<"./wall.get.json">
type Api(acess_token : string) = class
let create (acess_token:string) : getter =
fun method_name parameters ->
async {
let url = sprintf "https://api.vkontakte.ru/method/%s" method_name
let query = seq {
yield ("acess_token", acess_token)