Skip to content

Instantly share code, notes, and snippets.

View jeremyheiler's full-sized avatar

Jeremy Heiler jeremyheiler

View GitHub Profile
(require '[paprika.core] :as adn)
;; Assume t is your access token.
(def at {:access-token t})
;; The simple case allows the first argument to be a string.
(adn/create-post "This is a test" at)
;; For every other case, pass in a map.
(adn/create-post {:text "This is a test" :reply-to "123"} at)
@jeremyheiler
jeremyheiler / helo.clj
Last active December 18, 2015 23:49
Options...
;; Straighforward
(defn handle-helo
[session command]
[(-> session
(reset-session)
(assoc :client-host (:domain command)))
{:code 250 :text (:server-host session)}])
;; State monad style
;; Not sure if command needs to be closed over, though.
@jeremyheiler
jeremyheiler / get-line.clj
Last active December 19, 2015 10:28
Read a line that ends with a CRLF.
(defn get-line
[reader]
(loop [last-cr? false line (StringBuilder.)]
(let [i (.read reader)]
(if (neg? i)
(str line)
(let [c (char i)]
(if (and last-cr? (= c \newline))
(.substring line 0 (dec (.length line)))
(recur (= c \return) (.append line c))))))))
package main
import "code.google.com/p/go-tour/tree"
import "fmt"
func Walk2(t *tree.Tree, ch chan int) {
if t.Left != nil {
Walk2(t.Left, ch)
}
ch <- t.Value
@jeremyheiler
jeremyheiler / gist:6432956
Created September 4, 2013 05:05
Print the contents of a file to stdout.
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv)
{
if (argc == 1) return 0;
if (argc == 2) {
char *filename = argv[1];
FILE *fp = fopen(filename, "r");
if (!fp) {
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFFER_SIZE 5
struct reqdata
{
char *data;
size_t len;
@jeremyheiler
jeremyheiler / mc.lisp
Created September 17, 2013 03:57
My first lisp program.
; Missionaries and Cannibals
;-------------------------------------------------------------------------------
; main method
( defmethod mc ()
( establish-operators )
( setup )
( solve )
)
(defmacro apply (f arr)
`(f ~@arr))
(apply str ["foo" "bar" "baz"])
;; macroexpands to:
(str "foo" "bar" "baz")
@jeremyheiler
jeremyheiler / gist:6695635
Last active December 23, 2015 21:19
variable and function definitions for a javascript-based lisp?
;; javascripty
(var foo 42)
(var inc (function (x) (+ x 1)))
(function dec (x) (- x 1))
;; clojurey
(def foo 42)
(def inc (fn [x] (x + 1)))
(defn dec [x] (- x 1))
// var foo = bar = 42;
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {