Skip to content

Instantly share code, notes, and snippets.

Avatar
™️
Jonathaning

Jonathan Fischoff jfischoff

™️
Jonathaning
View GitHub Profile
View partition query and plan
postgres=# explain (analyze, buffers) UPDATE payloads
postgres-# SET state='dequeued'
postgres-# WHERE id in
postgres-# ( SELECT p1.id
postgres(# FROM payloads AS p1
postgres(# WHERE p1.state='enqueued'
postgres(# ORDER BY p1.modified_at ASC
postgres(# FOR UPDATE SKIP LOCKED
postgres(# LIMIT 1
postgres(# )
View partition creation function
CREATE OR REPLACE FUNCTION enqueue(count int8, x anyarray) RETURNS void AS $$
DECLARE
startValue int8;
lastValue int8;
currentValue int8;
partition_name text;
doubleCount int8;
BEGIN
doubleCount := 2 * count;
SELECT nextval('modified_index') INTO currentValue ;
View auto_explain_output.log
2019-12-29 21:13:35 GMT [42602]: LOG: duration: 2.476 ms plan:
Query Text: INSERT INTO users (email, password, name) VALUES ('example@example1.com', 'password', 'name1') RETURNING id
Insert on public.users (cost=0.00..0.02 rows=1 width=382) (actual time=2.471..2.472 rows=1 loops=1)
Output: id
Buffers: shared hit=9 read=11 dirtied=9
I/O Timings: read=1.879
-> Result (cost=0.00..0.02 rows=1 width=382) (actual time=1.100..1.100 rows=1 loops=1)
Output: nextval('users_id_seq'::regclass), clock_timestamp(), clock_timestamp(), 'example@example1.com'::character varying(140), '\x70617373776f7264'::bytea, 'name1'::text
Buffers: shared hit=9 read=4 dirtied=2
I/O Timings: read=1.028
View aroundAll.hs
aroundAll :: forall a. ((a -> IO ()) -> IO ()) -> SpecWith a -> Spec
aroundAll withFunc specWith = do
(var, stopper, asyncer) <- runIO $
(,,) <$> newEmptyMVar <*> newEmptyMVar <*> newIORef Nothing
let theStart :: IO a
theStart = do
thread <- async $ do
withFunc $ \x -> do
putMVar var x
View Lastoid.hs
-- I think this is a a monoid. Basically it is used to either mappend to a value or replace the value
data Lastoid a = Replace a | Mappend a | Nope
instance Semigroup a => Semigroup (Lastoid a) where
x <> y = case (x, y) of
(r@Replace {}, _ ) -> r
(Mappend a , Replace b) -> Replace $ a <> b
(Mappend a , Mappend b) -> Mappend $ a <> b
(Nope , x ) -> x
View WorkflowTest.hs
type WidgetFlow t m a = Workflow t (VtyWidget t m) a
testScreen
:: (Reflex t, Show a, Show b, Monad m)
=> a
-- ^ Input
-> (a -> VtyWidget t m (Event t b))
-- ^ Screen to test
-> (b -> WidgetFlow t m ())
-- ^ Next continuation
View advance.hs
-- What I am struggling to do is sequence to looping things. First I have a loop where the output is feed into the
-- next step as input until it completes. Then the next loop starts.
-- I doubt this works ... I'm trying to test it now ... anyway I don't like it and feel like
-- there must be an easier way.
advance :: (Adjustable t m, MonadHold t m, Monad m, MonadFix m)
=> m (Event t (Maybe a))
-- ^ initial
-> (a -> m (Event t (Maybe a)))
View delayOne.hs
delayOne :: (MonadHold t m, Reflex t) => Event t a -> m (Event t (a, a))
delayOne e = do
b <- hold Nothing $ Just <$> e
let eOld = W.catMaybes $ b <@ e
pure $ liftF2 (,) eOld e
@jfischoff
jfischoff / Fold.hs
Created Jul 15, 2019
Fold like thing with termination
View Fold.hs
-- The idea is to compose fold like things that can terminate. This is primarily so I can
-- make a Alternative instance that returns the first finished fold.
-- I copied much of this from foldl and folds but unlike those libraries you cannot call the `extractor` until the
-- fold is finished.
data StepState = Running | Finished
deriving (Eq, Show, Ord, Read, Generic)
anyFinished :: StepState -> StepState -> StepState
anyFinished x y = case (x, y) of
View relative filepath thingy
{-# LANGUAGE RecordWildCards #-}
module TH where
import Language.Haskell.TH
import System.FilePath
import Control.Monad ((<=<))
import System.Directory (getCurrentDirectory, canonicalizePath)
fileRelativeToAbsolute :: String -> Q Exp
fileRelativeToAbsolute = stringE <=< fileRelativeToAbsoluteStr
You can’t perform that action at this time.