Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Debug.Trace (traceShow)
import Data.List (minimumBy, sortBy, genericLength)
import Control.Monad ((=<<), liftM, liftM2)
import Data.Maybe (fromJust)
trace1 x = traceShow x x
@sinelaw
sinelaw / test-search.hs
Last active December 12, 2015 03:09
Added dynamic programming with parallelization
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Debug.Trace (traceShow)
import Data.List (minimumBy, sortBy, genericLength)
import Control.Monad ((=<<), liftM, liftM2)
import Data.Maybe (fromJust, isJust)
import System.IO (hPutStrLn, stderr)
import Control.Parallel (par, pseq)
@sinelaw
sinelaw / datepicker-focus.js
Last active August 29, 2019 13:46 — forked from jeffsheets/datepicker-focus.js
Fixes reopening of datepicker on IE <= 9 (not tested on IE 10) Changes to work for jQuery 1.9.1 and jQuery-ui 1.10.1: 1. don't use $.browser since it's deprecate. Instead use a var called isIE 2. simplify the handlers 3. use $.datepicker.setDefaults to affect ALL datepickers on the page
/*
After jquery ui datepicker selection, blur and change
events fire before focus is returned to the input field,
handling a quirk from IE browsers
*/
function setupDatepicker() {
// The 'isIE' var below requires an '.old-ie' class to be set on the html,
// for example:
// <!--[if lt IE 7]> <html class="old-ie lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
// <!--[if IE 7]> <html class="old-ie ie7 lt-ie9 lt-ie8"> <![endif]-->
/* license: https://opensource.org/licenses/MIT */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
namespace Behaviors {
interface IGetMethod { int GetValue(); }
interface ISetMethod { void SetValue(int value); }
interface IBothMethods : IGetMethod, ISetMethod { }
class BothMethods : IBothMethods
{
int _value;
@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