Skip to content

Instantly share code, notes, and snippets.

View ThomasLocke's full-sized avatar

Thomas Løcke ThomasLocke

View GitHub Profile
@ThomasLocke
ThomasLocke / passgen.hs
Created July 30, 2015 14:53
A Haskell noob trying to create sorta-kinda random passwords
import Control.Applicative
import System.Environment
import System.Exit
import System.Random
main = getArgs >>= parseArgs
-- Exit with success.
exit :: IO a
exit = exitWith ExitSuccess
@ThomasLocke
ThomasLocke / countSomething.hs
Created July 3, 2015 14:06
Lad os tælle ting i lister af ting!
-- Skriv en funktion der returnerer strengen:
-- This is an amazingly interesting sentence!
???
-- Skriv en funktion der returnerer hvor mange gange a findes i [a]
countSomething :: Eq a => a -> [a] -> Int
countSomething ???
-- Skriv ovenstående funktion i 3 udgaver:
-- 1. En der løser opgaven med list comprehension
@ThomasLocke
ThomasLocke / sniplet.dart
Created June 30, 2015 06:39
En lille Dart sniplet
import 'dart:convert';
import 'dart:io';
main(Args args) {
print(UTF8.decode(new File(args[0]).readAsBytesSync())
.split('AND')
.map((s) => s.trim())
.toList()
.join(' AND\n'));
}
@ThomasLocke
ThomasLocke / haskell180615.hs
Created June 18, 2015 11:36
Haskell udfordringer 180615
-- Alle steder i ser ??? skal i skrive noget.
-- For bonuspoint:
-- Læs mere om List Comprehension her http://learnyouahaskell.com/starting-out (langt nede på siden)
-- Opgave 1
-- Definer to type synonymer kaldet Name og Names.
-- Name skal være et synonym for String og Names for liste af Name.
???
???
@ThomasLocke
ThomasLocke / printBook.hs
Created May 22, 2015 07:23
Playing around with Haskell type/data and a couple of simple functions
--
-- Lets pretty print a Book!
--
-- A couple of type synonyms for readability.
type Title = String
type Authors = [String]
-- Our Book data type.
-- A book consists of an isbn number, a title and a list of authors.
library shelfmiddleware.checktoken;
import 'headers.dart';
import 'token.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf_path/shelf_path.dart';
final shelf.Middleware checkToken = shelf.createMiddleware(requestHandler: _passOrForbid);
@ThomasLocke
ThomasLocke / gist:8a64b8487e95f4c34555
Created October 12, 2014 15:15
shelf.middleware.headers.dart
library shelfmiddleware.headers;
import 'dart:io' show HttpHeaders;
const Map<String, String> textHtmlHeader = const {HttpHeaders.CONTENT_TYPE: 'text/html'};
const Map<String, String> CORSHeader = const {'Access-Control-Allow-Origin': '*'};
@ThomasLocke
ThomasLocke / gist:5ba07e9ffbd689399fd4
Created October 12, 2014 15:12
shelf.middleware.token.dart
library shelfmiddleware.token;
final List<String> _validTokens = new List<String>();
bool isValid(String token) => _validTokens.contains(token);
String getToken() {
final String token = new DateTime.now().millisecondsSinceEpoch.toString();
_validTokens.add(new DateTime.now().millisecondsSinceEpoch.toString());
@ThomasLocke
ThomasLocke / gist:a79096f4a369d8c310c6
Created October 12, 2014 15:10
shelf.middleware.handlers.dart
library shelfmiddleware.handlers;
import 'headers.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf_path/shelf_path.dart';
shelf.Response app(shelf.Request request) {
final String myToken = getPathParameter(request, 'token');
@ThomasLocke
ThomasLocke / gist:491c357a21082078b2ab
Created October 12, 2014 15:07
shelf.middleware.routes.dart
library shelfmiddleware.routes;
import 'handlers.dart' as handler;
import 'package:shelf_route/shelf_route.dart';
final Router routes = new Router()
..get('/app{?token}', handler.app)
..get('/foo{?token}', handler.foo);