Skip to content

Instantly share code, notes, and snippets.

@homam
homam / Utils.cs
Last active August 20, 2019 16:11
My Big 2010s C# Utils
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Net.Mail;
using System.Web;
using System.Xml.Serialization;
fix-row = (a) ->
date = new Date (new Date a["Row Labels"] .valueOf! + (4 * 1000 * 3600))
{
date
visits: parse-float a["Visits Count"]
visitsCost: parse-float a["Visits Cost"]
totalCost: parse-float a["Total Cost"]
subscribers: parse-float a["Subscribers Count"]
subscribersCost: parse-float a["Subscribers Cost"]
eCPS: parse-float a["eCPS"]
@homam
homam / Shell-Commands-Parser.ls
Created March 20, 2016 12:52
Shell Command Parser in LiveScript using Monadic Combinators
is-digit = (c) -> 48 <= (c.char-code-at 0) <= 57
is-space = (c) -> code = c.char-code-at 0 ; [9, 10, 32] |> any (== code)
is-lower-letter = (c) ->
return false if !c
code = c.char-code-at 0 ; code >= 97 and code <= 122
is-upper-letter = (c) -> code = c.char-code-at 0 ; code >= 65 and code <= 90
@homam
homam / ReaderT-config-StateT-state-Identity.hs
Created January 21, 2016 07:19
ReaderT config (StateT state Identity)
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.Trans
import Control.Monad.Trans.State
import Control.Monad.Trans.Reader
import Control.Monad.Identity
import qualified Control.Monad.State as S
import qualified Control.Monad.Reader as R
@homam
homam / StateT-Random-Generation.hs
Created January 21, 2016 07:19
StateT Random Generation
import System.Random
import Control.Monad.Trans
import Control.Monad.Trans.State
import Control.Monad.Identity
import qualified Control.Monad.State as S
type Eval a g = StateT (g Identity) a
runEval :: (RandomGen g) => g -> StateT g Identity a -> (a, g)
@homam
homam / breadth-first-tree-traversal.hs
Created January 21, 2016 07:18
breadth first tree traversal
import System.Directory (getDirectoryContents, doesDirectoryExist)
data Tree a = Directory a [Tree a] | File a deriving (Show)
makeTheTree :: FilePath -> IO (Tree FilePath)
makeTheTree path = do
isDirecotry <- doesDirectoryExist path
if not isDirecotry then
return $ File path
else do
@homam
homam / AR.hs
Created January 21, 2016 07:17
(a -> r) instance
{-# LANGUAGE FlexibleInstances #-}
class Arg a where
collect' :: [String] -> a
-- extract to IO
instance Arg (IO ()) where
collect' = mapM_ putStrLn
-- extract to [String]
import Control.Monad
import Data.List (intercalate)
facs :: [Integer]
facs = 1 : 1 : 2 : 6 : zipWith (*) [4 ..] (drop 2 . tail $ facs)
fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
main = do
import SetInterval
import SetIntervalT
import Control.Concurrent
import Control.Exception
import Control.Monad.State
sprint :: (Show b) => MVar () -> b -> IO ()
sprint mvar b = do
putMVar mvar ()
print b
@homam
homam / DefaultKeyBinding.dict
Created November 18, 2015 16:16
OSX DefaultKeyBinding.dict
{
"~a" = ("insertText:", "α");
"~b" = ("insertText:", "β");
"~g" = ("insertText:", "γ");
"~i" = ("insertText:", "ι");
"~k" = ("insertText:", "κ");
"~@k" = ("insertText:", "κ");
"~^d" = ("insertText:", "∂");
"~d" = ("insertText:", "δ");
"~$D" = ("insertText:", "Δ");