Skip to content

Instantly share code, notes, and snippets.

@LukaJCB
LukaJCB / TaglessOptimize.scala
Last active May 3, 2019 10:43
Optimize an Applicative Program with Tagless Final
trait KVStore[F[_]] {
def get(key: String): F[Option[String]]
def put(key: String, a: String): F[Unit]
}
class TestInterpreter() extends KVStore[IO] {
def get(key: String): IO[Option[String]] = IO {
println("Hit network!")
Option(key + "!")
@debasishg
debasishg / gist:f473167ac91b2af4949c6340d4aa0c1b
Created August 12, 2017 21:49 — forked from runarorama/gist:78c8fefbab74701afab3
Playing around with "Finally Tagless, Partially Evaluated" in Scala
// Finally tagless lambda calculus
object Final {
def varZ[A,B](env1: A, env2: B): A = env1
def varS[A,B,T](vp: B => T)(env1: A, env2: B): T = vp(env2)
def b[E](bv: Boolean)(env: E): Boolean = bv
def lam[A,E,T](e: (A, E) => T)(env: E): A => T = x => e(x, env)
def app[A,E,T](e1: E => A => T, e2: E => A)(env: E): T = e1(env)(e2(env))
def testf1[E,A](env: E): Boolean =
app(lam[Boolean,E,Boolean](varZ) _, b(true))(env)

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@sebmarkbage
sebmarkbage / ReactCanvasDrawing.js
Created July 25, 2014 19:14
Canvas Drawing Example
/** @jsx React.DOM */
var Graphic = React.createClass({
componentDidMount: function() {
var context = this.getDOMNode().getContext('2d');
this.paint(context);
},
componentDidUpdate: function() {
@runarorama
runarorama / gist:78c8fefbab74701afab3
Last active June 24, 2018 17:06
Playing around with "Finally Tagless, Partially Evaluated" in Scala
// Finally tagless lambda calculus
object Final {
def varZ[A,B](env1: A, env2: B): A = env1
def varS[A,B,T](vp: B => T)(env1: A, env2: B): T = vp(env2)
def b[E](bv: Boolean)(env: E): Boolean = bv
def lam[A,E,T](e: (A, E) => T)(env: E): A => T = x => e(x, env)
def app[A,E,T](e1: E => A => T, e2: E => A)(env: E): T = e1(env)(e2(env))
def testf1[E,A](env: E): Boolean =
app(lam[Boolean,E,Boolean](varZ) _, b(true))(env)
@igorw
igorw / mutation.php
Created May 5, 2014 18:28
Self-modifying quasi-quine. Try running it, then piping the output into PHP. Then piping that output into PHP again. Then piping that output into PHP again. Then piping that output into PHP again. Then piping that output into PHP again. Then piping that output into PHP again.
<?php
$data = <<<'DATA'
$program = <<<PROGRAM
<?php
\$data = <<<'DATA'\n$data\nDATA;
$data
PROGRAM;
$n = 0;
if ($n >= 5) {
@debasishg
debasishg / gist:8172796
Last active March 15, 2024 15:05
A collection of links for streaming algorithms and data structures

General Background and Overview

  1. Probabilistic Data Structures for Web Analytics and Data Mining : A great overview of the space of probabilistic data structures and how they are used in approximation algorithm implementation.
  2. Models and Issues in Data Stream Systems
  3. Philippe Flajolet’s contribution to streaming algorithms : A presentation by Jérémie Lumbroso that visits some of the hostorical perspectives and how it all began with Flajolet
  4. Approximate Frequency Counts over Data Streams by Gurmeet Singh Manku & Rajeev Motwani : One of the early papers on the subject.
  5. [Methods for Finding Frequent Items in Data Streams](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.187.9800&amp;rep=rep1&amp;t
<?php
const StateManager = '';
const State = '';
const HARMFUL = 'harmful';
function getConsiderationSetter($subject, $state) {
global $consideration;
$consideration = "$subject considered $state";
}
<?php
spl_autoload_register(function ($name) {
// $exp will be the name of the class without the \with\traitname part => array_splice
$exp = explode("\\", $name);
// serach from end
$index = array_search("with", array_reverse($exp, true));
if (!$index || $index - 1 == count($exp)) // also fail when value is 0
return false;
@igorw
igorw / quine.php
Created October 17, 2013 21:48
Quine, from Tom Stuart's "Understanding Computation".
<?php
$data = <<<'DATA'
$program = <<<PROGRAM
<?php
\$data = <<<'DATA'\n$data\nDATA;
$data
PROGRAM;
echo $program;
DATA;