Skip to content

Instantly share code, notes, and snippets.

View peterschwarz's full-sized avatar

Peter Schwarz peterschwarz

View GitHub Profile
@peterschwarz
peterschwarz / handler.clj
Last active August 29, 2015 13:56
Hello Session World
(ns hello-world.handler
(:use compojure.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]
[ring.util.response :as resp]
[clojure.data.json :as json]))
(defn generate-response [data & [status]]
{:status (or status 200)
:body (str "<div>Hello <strong>" (:hello data) "</strong></div><div>We seen you <em>" (inc (:count data)) "</em> time(s)</div>")
@peterschwarz
peterschwarz / mult_example.clj
Created April 16, 2014 23:32
Core.async `mult` example
(require '[clojure.core.async :refer [chan timeout >!! <!! alts!! mult tap]])
(defn td [ch]
(first (alts!! [ch (timeout 100)])))
(def c (chan 10))
(>!! c :foo) ; true
@peterschwarz
peterschwarz / subl.sh
Last active August 29, 2015 14:00
subl command line util
#!/bin/sh
nohup ~/Applications/sublime-text-2/sublime_text $1 >/dev/null 2>&1 &
@peterschwarz
peterschwarz / doAll.js
Created August 1, 2014 18:38
Do all underscore addition
_.doAll = function(fn) {
var fns = Array.prototype.slice.call(arguments);
return function() {
var self = this;
var target_args = Array.prototype.slice.call(arguments);
return _.map(fns, function(fn) {
return fn.apply(self, target_args)
});
@peterschwarz
peterschwarz / list_classpath.clj
Last active March 25, 2016 14:45
List current classpath in clojure
(defn current-classpath []
(->> (ClassLoader/getSystemClassLoader) (.getURLs) seq (map #(.getFile %))))
(let [bisect-by (juxt filter remove)]
(bisect-by odd? [1 2 3 4 5]))
; => [(1 3 5) (2 4)]
@peterschwarz
peterschwarz / keybase.md
Last active November 4, 2016 14:41
keybase verification

Keybase proof

I hereby claim:

  • I am peterschwarz on github.
  • I am pschwarz (https://keybase.io/pschwarz) on keybase.
  • I have a public key ASDDELxVW0VvTx5AZSS-J6bpiFOUQF3lV8wTgezhdkqcIQo

To claim this, I am signing this object:

@peterschwarz
peterschwarz / playground.rs
Created May 18, 2018 14:03 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::Mutex;
#[derive(Default)]
struct StringManagerPrimative {
pub map: HashMap<String, String>,
}
impl StringManagerPrimative {
@peterschwarz
peterschwarz / useful_sawtooth_cmds.md
Last active August 12, 2018 22:39
Useful Sawtooth Development Commands

Useful commands for Sawtooth Core Developers

Python Linting

Use docker to run the linter

$ docker-compose -f docker/compose/run-lint.yaml up lint-python
@peterschwarz
peterschwarz / playground.rs
Created September 12, 2018 13:58 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#[derive(Default)]
struct X {
a: String,
b: String,
c: String,
}
macro_rules! reject_empty {
($obj:ident, $first_field:tt, $($field:tt),*) => {
{