Skip to content

Instantly share code, notes, and snippets.

View mxswd's full-sized avatar

Maxwell mxswd

View GitHub Profile
@mxswd
mxswd / Shorthash.hs
Created June 6, 2013 14:11
Hashing!
module Shorthash where
import Data.Digest.Pure.MD5 (md5)
import qualified Data.ByteString.Base64 as B64
import qualified Data.Serialize as B
import qualified Data.Text.Lazy as L
import qualified Data.Text.Lazy.Encoding as T
import qualified Data.ByteString as BS
@mxswd
mxswd / Redis.hs
Created June 6, 2013 22:00
Data.Text interface to hedis (Redis)
{-# LANGUAGE NoMonomorphismRestriction, OverloadedStrings #-}
module Backend.Redis (connect, get, set, R.Connection) where
import Control.Monad.IO.Class
import qualified Database.Redis as R
import Control.Applicative
import qualified Data.Text.Lazy as L
import qualified Data.Text.Lazy.Encoding as L
import qualified Data.Text.Encoding as T
import Network.CGI
import System.IO
import Data.List
main :: IO ()
main = runCGI (handleErrors cgiMain)
cgiMain = do
uri <- getInputs
let urjson = map (\(x, y) -> "\"" ++ x ++ "\": \"" ++ y ++ "\"") uri
newtype ActionM a = AM { runAM :: ErrorT ActionError (ReaderT ActionEnv (StateT Response IO)) a }
deriving ( Monad, MonadIO, Functor
, MonadReader ActionEnv, MonadState Response, MonadError ActionError)
-- backend
get :: B.Connection -> L.Text -> ActionM (Maybe L.Text)
get b k = do
let code = ensureUrl k
val <- B.get b (c_of code)
case val of
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]];
[self.webView loadRequest:request];
bool __block inRac = false;
[RACObserve(self, webView.scrollView.contentSize)
subscribeNext:^(id x) {
if (!inRac) {
inRac = true;
self.webView.scrollView.contentSize = CGSizeMake(self.webView.frame.size.width, self.webView.scrollView.contentSize.height);
inRac = false;
@mxswd
mxswd / gist:6290258
Last active December 21, 2015 10:09
main = do
let xs = [0..1024]
print $ foldl (\x y -> length y + x) 0 $ lsubs xs
lsubs [] = []
lsubs (x:xs) = (foldr (\y ys -> (x, y) : ys) [] xs) : lsubs xs
-- for people too lazy to read the chmod man page
import Graphics.Input as Input
import Window
scene : (Int, Int) -> Element -> [Element] -> Element
scene (w, h) strInput strVal = flow down
[ container w 100 topLeft strInput,
container w (h - 100) topLeft (case strVal of
[] -> plainText "wtf"
xs -> flow down (map (width 200) xs))]
@mxswd
mxswd / a How Do.md
Last active December 22, 2015 02:39

Set static IP on the network for the server. Enable L2TP VPN. Port forward TCP 1723, UDP 500, UDP 1701, UDP 4500.

{-#LANGUAGE GADTs, EmptyDataDecls, DataKinds, KindSignatures #-}
-- kind
data ListCont = Empty | NonEmpty
data SafeList a (b :: ListCont) where
Nil :: SafeList a Empty
Cons:: a -> SafeList a b -> SafeList a NonEmpty
safeHead :: SafeList a NonEmpty -> a
module Main where
import System.IO
import System.Exit
import System.Process
import System.Environment
main :: IO ()
main = do
args <- getArgs