Skip to content

Instantly share code, notes, and snippets.

View zippy's full-sized avatar

Eric Harris-Braun zippy

View GitHub Profile
@zippy
zippy / make-test-failing
Created March 12, 2017 15:26
failing make test
eric@finkomatic:~/go/src/github.com/metacurrency/holochain$ make test
gx install --global
installation of dep go-semver complete!
installation of dep dns complete!
installation of dep go-text complete!
installation of dep go-net complete!
installation of dep mdns complete!
installation of dep go-randbuf complete!
installation of dep go-msgio complete!
installation of dep go-crypto complete!
go get github.com/libp2p/go-libp2p-swarm
# github.com/libp2p/go-libp2p-conn
../../libp2p/go-libp2p-conn/dial.go:134: cannot use pconn (type transport.Conn) as type conn.Conn in assignment:
transport.Conn does not implement conn.Conn (missing ID method)
../../libp2p/go-libp2p-conn/listen.go:104: cannot use pc (type transport.Conn) as type conn.Conn in assignment:
transport.Conn does not implement conn.Conn (missing ID method)
//run system commands
#include <stdio.h>
char *doSys(char *cmd) {
FILE *pipe = popen(cmd, "r");
if (!pipe) {return "err"; }
int sz = 1000;
int remaining = sz;
char *buffer = malloc(sz);
char buf[255];
while (fgets(buf, 255, pipe) != NULL) {
@zippy
zippy / adding shuffle to vector
Created September 19, 2013 01:06
Failed attempt to add shuffle to Rust vec
pub trait MutableVector<'self, T> {
fn shuffle(self);
}
impl<'self, T> MutableVector<'self, T> for &'self mut [T] {
fn shuffle(self) {
let l=self.len();
let mut i=l;
let mut rng = rand::rng();
loop {
@zippy
zippy / gist:1276936
Created October 11, 2011 00:13
clojurescript and goog.ui.select
(defn make-select [elem-id]
(let [select (goog.ui.Select. "Heading")
select-elem (d/element (keyword (str "div#" elem-id)))]
(.addItemAt select (goog.ui.MenuItem. "Item 1") 0)
(.addItem select (goog.ui.Option. "Item 2"))
(.render select select-elem)
select-elem
)
)
@zippy
zippy / gist:1268340
Created October 6, 2011 19:12
http-handler
(defn make-http-handler [host _r]
(app
["api"] {:post (fn [request]
(try
(let [b (trim (bytes->string (:body request)))
{command :cmd params :params} (clojure.contrib.json/read-json b)]
(println (str "POST REQUEST: from " (:remote-addr request) " for: " b))
{:status 200
:headers {"content-type" "application/json"
"Access-Control-Allow-Origin" "*"}
@zippy
zippy / gist:1232866
Created September 21, 2011 18:19
clojurescript closure problem
; This fails:
(doseq [hid ["a" "b" "c"]]
(goog.dom.appendChild (goog.dom.$ "some-element-id") (goog.dom.createDom "div" (.strobj {"id" hid}) (str "Test-"hid)))
(goog.events.listen (goog.dom.$ hid) goog.events.EventType.CLICK, (fn [e] (js/alert hid))))
;This works:
(defn hidfn [hid]
(fn [e] (js/alert hid))
)
(doseq [hid ["a" "b" "c"]]
@zippy
zippy / gist:1223636
Created September 17, 2011 04:52
clojurescript getValue bug
(ns test.core
(:require [clojure.browser.dom :as dom]
[goog.ui.Dialog :as Dialog]
[goog.events :as events]
[goog.ui.LabelInput :as LabelInput]
))
(def d (goog.ui.Dialog.))
(def l (goog.ui.LabelInput. "User name"))
@zippy
zippy / cmp.clj
Created May 20, 2011 01:21
compojure problem
(ns cmp.core
(:use compojure.core, ring.adapter.jetty)
(:require [compojure.route :as route]
[compojure.handler :as handler])
)
(defn view-form []
(str "<html><head></head><body>"
"<form method=\"post\">"
@zippy
zippy / instantiation_exception_error.clj
Created May 11, 2011 14:58
clojure macro instantiation error
(defmacro make-obj [n & args]
(let [name (if (instance? clojure.lang.Symbol n) n (eval n))]
`{(keyword '~name) [~@args]} ))
(make-obj bar :foo) ; => {:bar [:foo]}
(make-obj (symbol (str (name :bar))) :foo) ; => {:bar [:foo]}
(defmacro make-fn [n & b] `(defn ~n ~@b))
(make-fn keyword-maker [k] (make-obj (symbol (str (name k))) :foo)) ;=> Thrown class java.lang.InstantiationException