Skip to content

Instantly share code, notes, and snippets.

View tlaitinen's full-sized avatar
💭
vacation

Tero Laitinen tlaitinen

💭
vacation
View GitHub Profile
@tlaitinen
tlaitinen / session.js
Created January 11, 2013 13:59
A simple jQuery module for authentication against Yesod.Auth.HashDB.
"use strict";
define({
session: function() {
return {
status: '',
user: '',
baseUrl: '',
login: function(baseUrl, username, password, doneCallback, failCallback) {
var ses = this;
ses.baseUrl = baseUrl;
@tlaitinen
tlaitinen / PathPieceInstances.hs
Last active July 29, 2020 12:35
Additional Web.PathPieces.PathPiece instances to deserialize Int32, Word32, Word64, Double, Bool, TimeOfDay, UTCTime and ZonedTime
safeRead :: forall a. Read a => Text -> Maybe a
safeRead s = case (reads $ T.unpack s) of
[(v,_)] -> Just v
_ -> Nothing
instance PathPiece Int32 where
fromPathPiece s =
case Data.Text.Read.decimal s of
Right (i, _) -> Just i
Left _ -> Nothing
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleContexts #-}
module Api.Database where
{-# LANGUAGE PackageImports #-}
module AES (encryptFile, decrypt) where
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.Maybe
import qualified "cryptonite" Crypto.Cipher.AES as C
import qualified "cryptonite" Crypto.Cipher.Types as C
import qualified "cryptonite" Crypto.Error as C
import qualified Crypto.Nonce as N
import xs from 'xstream';
import isolate from '@cycle/isolate';
import {div, button, input} from '@cycle/dom';
function intent(domSource, httpSource) {
const errorObj = { httpError: true }
const username$ = domSource.select('.username').events('input')
.map(ev => ev.target.value).startWith('')
const password$ = domSource.select('.password').events('input')
.map(ev => ev.target.value).startWith('')
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleContexts #-}
module Api.Database where
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Api.User where
import Servant
import Models
import Enums
import Config
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RecordWildCards #-}
module OnlySecure where
@tlaitinen
tlaitinen / OpenCV-face-follow-test.cpp
Created January 18, 2017 10:08
OpenCV test to detect and follow faces in a video
#include "opencv2/objdetect.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/face.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/core_c.h"
#include "opencv2/videoio/videoio_c.h"
#include "opencv2/highgui/highgui_c.h"
CREATE FUNCTION has_role (userId BIGINT, userGroupId BIGINT, role TEXT)
RETURNS BOOLEAN
AS
$$
SELECT EXISTS (
SELECT 1
FROM role
WHERE user_id = $1
AND user_group_id = $2
AND role = $3