Skip to content

Instantly share code, notes, and snippets.

@ekmett
ekmett / monads for plt-racket
Created June 26, 2010 05:06
Monads for PLT Racket
(module monad scheme
(require "curry.ss")
;; i'm too lazy to repeat this pattern for now.
(define-syntax init-public
(syntax-rules ()
((_) (begin))
((_ (m default) ms ...) (begin
(init-field (m default))
(public (internal-m m))
(define (internal-m . rest) (apply (get-field m this) rest))
@willtim
willtim / Parser.hs
Created November 2, 2010 22:48
Applicative Parsing
import Data.Maybe
import Text.Printf
import Control.Applicative
data Expr = Term Int | Op Operator Expr Expr | Var String
deriving (Show, Eq)
data Operator = Sum | Mult | Sub | Div
deriving (Show, Eq)
@danking
danking / gist:1068185
Created July 6, 2011 19:55
A very simple example showing how to use Racket's lexing and parsing utilities
#lang racket
(require parser-tools/lex
(prefix-in re- parser-tools/lex-sre)
parser-tools/yacc)
(provide (all-defined-out))
(define-tokens a (NUM VAR))
(define-empty-tokens b (+ - EOF LET IN))
(define-lex-trans number
(syntax-rules ()
@pjlsergeant
pjlsergeant / gist:1803656
Created February 11, 2012 19:07
Game of Life in 131 characters of Perl.
#!perl
use strict;
# Accepts a grid size, and a list representing the grid. 131
# characters. RUNS UNDER STRICTURES BABY YEAH.
my$life=sub{$a=shift;map{$b=$_[$_];my$n;$n+=$_[$_]for($_-$a-1..$_-$a+1,$_-1,$_+1,$_+$a-1..$_+$a+1);$n+$b==3||$b&&$n==4||0}0..$#_};
my $result = join '', $life->( 5, qw/
@rsimoes
rsimoes / linearly-typed.pl
Created February 22, 2012 14:48
Long-winded linearly typed variables
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dump;
use Data::Alias "alias";
use Scalar::Util qw(weaken isweak);
my $foo = ["a".."z"];
alias my @bar = @$foo;
npto :: (Integral a) => a -> [a]
npto x = [2,3] ++ concat [[x*6-1,x*6+1] | x <- [1..n]]
where n = ((+1) . round . sqrt . fromIntegral $ x) `div` 6
factors :: (Integral a) => a -> [a]
factors 1 = []
factors x = least : factors (x `div` least)
where least = head $ fs ++ [x]
fs = filter ((==0) . mod x) . npto $ x
@timjb
timjb / cloud-haskell-operational-transformation.hs
Created October 14, 2012 19:54
Simulation of Operational Transformation with Cloud Haskell
{-
This is a simple simulation of OT with Cloud in which all slaves generate
and apply random operations. It should work in theory. In practice, however
I wasn't apply to test it because my installation of distributed-process is
apparently broken. Specifically, `spawn` doesn't seem to work (I tested it
with some examples from the Well-Typed blog).
This code depends on https://github.com/timjb/haskell-operational-transformation.
-}
@pauloricardomg
pauloricardomg / cors.nginxconf
Last active March 8, 2024 18:31
Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
#
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
#
# Based on:
# * http://blog.themillhousegroup.com/2013/05/nginx-as-cors-enabled-https-proxy.html
# * http://enable-cors.org/server_nginx.html
#
server {
@Fuuzetsu
Fuuzetsu / hackagedocs
Last active December 13, 2022 22:40
Script for generating and uploading missing documentation for your Hackage packages. Now with fixed package links and contents page.
#!/usr/bin/env bash
cabal configure && cabal build && cabal haddock --hyperlink-source \
--html-location='/package/$pkg-$version/docs' \
--contents-location='/package/$pkg'
S=$?
if [ "${S}" -eq "0" ]; then
cd "dist/doc/html"
DDIR="${1}-${2}-docs"
cp -r "${1}" "${DDIR}" && tar -c -v -z --format=ustar -f "${DDIR}.tar.gz" "${DDIR}"
CS=$?
@strezh
strezh / GStreamer-1.0 some strings.sh
Last active October 2, 2023 09:00
GStreamer-1.0 personal cheat sheet
#!/bin/bash
# play YUV444 FULL HD file
gst-launch-1.0 -v filesrc location=size_1920x1080.yuv ! \
videoparse width=1920 height=1080 framerate=25/1 format=GST_VIDEO_FORMAT_Y444 ! \
videoconvert ! \
autovideosink
# play YUV422 FULL HD file
gst-launch-1.0 -v filesrc location=size_1920x1080.yuv ! \