Skip to content

Instantly share code, notes, and snippets.

@expede
expede / gist:8712eba17daa3980e352
Last active October 26, 2017 22:35
What is the Free Monad + Interpreter pattern?
-- Just the code from http://programmers.stackexchange.com/a/242803
-- ...I find it useful to type this stuff out. Weird, I know.
data DSL next = Get String (String -> next)
| Set String String next
| End
p1 :: DSL (DSL (DSL next))
p1 = Get "foo" $ \foo -> Set "bar" foo End
@jeapostrophe
jeapostrophe / ab.log
Created April 28, 2015 10:52
Responding to requests concurrently in the Racket Web server
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: Racket
Server Hostname: localhost
Server Port: 9000
@x
x / atomic-cache-example.clj
Created April 22, 2015 16:08
Atomic clojure.cache example
(require '[[clojure.cache :as cache]
[clojure.string :as string]
[cb-statsd :as statsd]])
(def STATSD_SAMPLE_RATE 0.01)
(defn get-statsd-path
[f]
(as-> (str (type f)) fname ;; returns something like "class namespace$foo"
(last (string/split fname #" ")) ;; parse out the "class "
@jhass
jhass / .rubocop.yml
Last active January 7, 2025 19:23
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
@jdeng
jdeng / pdf2img.html
Created February 11, 2015 02:54
pdf to image using pdf.js
<html>
<body>
<script type="text/javascript" src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
<script type="text/javascript">
var url = "https://docs.google.com/document/export?format=pdf&id=1ML11ZyyMpnAr6clIAwWrXD53pQgNR-DppMYwt9XvE6s&token=AC4w5Vg7fSWH1Hq0SgNckx4YCvnGPaScyw%3A1423618416864";
var pages = [], heights = [], width = 0, height = 0, currentPage = 1;
var scale = 1.5;
function draw() {
@nikAizuddin
nikAizuddin / NASMx86: Allocate heap memory
Created October 12, 2014 22:58
Example using brk() system call for dynamic memory allocations
; 1 2 3 4 5 6 7
;01234567890123456789012345678901234567890123456789012345678901234567890
;=======================================================================
;+---------------------------------------------------------------------+
;| |
;| Example using brk() system call for dynamic memory allocations. |
;| |
;| DON'T CONFUSE that brk() used in C Function is different with brk() |
;| systemcall (systemcall 45 for x86 ASM). |
;| |
@Khaledgarbaya
Khaledgarbaya / Hello_Triangle.cpp
Created October 4, 2014 22:28
Hello Triangle Sample With SDL in OpenGL ES 2 (IOS)
#include "SDL.h"
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#include <iostream>
#include <string>
#include <memory>
using namespace std;
GLuint programObject;
class Graphics
@john2x
john2x / 00_destructuring.md
Last active April 10, 2025 15:15
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@staltz
staltz / introrx.md
Last active April 21, 2025 04:15
The introduction to Reactive Programming you've been missing
# Copyright (c) 2014 Lukas Fittl <[email protected]>
#
# Released in the public domain - fork as you wish.
require 'rubygems'
require 'mixlib/cli'
require 'pg'
require 'pg_query'
require 'curses'