Skip to content

Instantly share code, notes, and snippets.

@sinelaw
sinelaw / gist:9084984
Last active August 29, 2015 13:56
Super-hacky workaround for missing TVF support in EF code first, using an interceptor to rewrite a table name as a TVF function call
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure.Interception;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics;
using System.Linq;
using System.Text;
data CvSize = CvSize { sizeWidth :: CInt, sizeHeight :: CInt }
deriving (Show, Eq)
instance Storable CvSize where
sizeOf _ = (#size CvSize)
alignment _ = alignment (undefined :: CInt)
peek ptr = do
w <- (#peek CvSize, width) ptr
h <- (#peek CvSize, height) ptr
@sinelaw
sinelaw / Test.hs
Last active August 29, 2015 14:05
drafty draft
module Test where
import Data.Either(isLeft, lefts, isRight)
data Type = Unknown | JNumber | JString | JRegex | JArray Type | JObject [(String, Type)] | JFunc [Type] Type
data Expr = LitNumber Double | LitString String | LitRegex String | LitArray [Expr] | LitObject [(String, Expr)]
| Var String -- TODO: perhaps there should only be Property (and for function scopes use a hidden base obj?)
| Plus Expr Expr | Minus Expr Expr
| Assign Expr Expr
-- | Property Expr String
@sinelaw
sinelaw / out.hs
Last active August 29, 2015 14:06
Expr (Call (Expr (LitFunc ["x"]
(Expr (Var "x")
(Right Context {parent = Context {parent = Context {parent = Global,
vars = [],
curType = Top},
vars = [("x",
TVar "x")],
curType = Top},
vars = [],
curType = TVar "x"})))
module Test where
import Data.Maybe
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Maybe(MaybeT(..))
import Control.Monad.State(State, runState, forM, get, put)
positiveOnly :: Int -> Maybe Int
Started GET "/api/system_status?_=1412070154562" for 127.0.0.1 at 2014-09-30 12:42:34 +0300
Processing by Api::V1::SystemStatusesController#index as JSON
Parameters: {"_"=>"1412070154562"}
LocalUser Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ('LocalUser') AND "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1
Completed 500 Internal Server Error in 2ms (Views: 0.1ms | ActiveRecord: 0.2ms)
@sinelaw
sinelaw / wikinews.hs
Last active August 29, 2015 14:07
tagsoup web scraping demo
module WikiNews where
import Network.HTTP(simpleHTTP, getRequest, getResponseBody)
import Data.List(isInfixOf, intersperse)
import Data.Char(isSpace, toLower)
import Control.Category((>>>))
import System.Random(getStdGen)
-- from package tagsoup:
@sinelaw
sinelaw / debounce.js
Created November 13, 2014 14:20
debouncer
function debounce(f, millis) {
var ready = true;
var timeoutId;
var lastMissed;
function resetTimeout(){
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(function() {
if (lastMissed) {
lastMissed();
}
@sinelaw
sinelaw / test.js
Last active August 29, 2015 14:10
inference
// (c -> c)
// c
var id = function(x) { return x; };
// (i -> i)
// TNumber
var num = id(3);
// (n -> n)
// TString
var str = id('a');
@sinelaw
sinelaw / FixT.hs
Created December 25, 2014 20:45
fixed-point type
{-# LANGUAGE FlexibleContexts, FlexibleInstances #-}
module FixT where
data Expr = Val
| Divide Expr Expr
| Times Expr Expr
deriving Show
flipDivide :: Expr -> Expr
flipDivide Val = Val