Skip to content

Instantly share code, notes, and snippets.

That’s a lot to take in! No wonder we got it wrong! We’ll take it slow, and look at the arguments.

(condp (* temp time) <

Our pred was (* temp time) (a Double), and our expr was the comparison function <. For each clause, (pred test-expr expr) is evaluated, so that would expand to something like

((* temp time) 400 &lt; )
@pbostrom
pbostrom / pmap.clj
Last active August 29, 2015 14:14
Concurrency bugs with with-redefs and deftest
;; with-redefs
``` clojure
(defn print-it []
(println "don't print this"))
(defn dont-print [x]
(with-redefs [print-it (constantly nil)]
(print-it)))
(defn -main []
```clojure
(defn print-it []
(println "don't print this"))
(defn dont-print [x]
(with-redefs [print-it (constantly nil)]
(print-it)))
(defn -main []
(doall (pmap dont-print (range 1000)))

1. with-redefs is not thread safe. As explained in the doc string, the changes will be visible in all threads. What's not obvious though is that the act of restoring the original values of the Vars will also be visible across all threads.

clojure.core/with-redefs
([bindings & body])
Macro
Added in 1.3
  binding => var-symbol temp-value-expr

  Temporarily redefines Vars while executing the body.  The
  temp-value-exprs will be evaluated and each resulting value will

Keybase proof

I hereby claim:

  • I am pbostrom on github.
  • I am pbostrom (https://keybase.io/pbostrom) on keybase.
  • I have a public key ASAINjnms6Tr5cD0SeBjfDzEgBzZjvyM6A1R9rJahOC5qwo

To claim this, I am signing this object:

@pbostrom
pbostrom / cloudwatch_health.sh
Last active July 17, 2018 19:25
Monitor your gaiad validator
#!/bin/bash
aws cloudwatch put-metric-data --metric-name UnhealthyValidator\
--value $1 --namespace "Cosmos" --region us-east-1
@pbostrom
pbostrom / cljs-npm.md
Last active March 8, 2024 07:53
Loading third-party npm modules in ClojureScript

Loading third-party npm modules in ClojureScript

This example shows how to load the re-resizable npm module which provides a resizable React component. Requires the lein-npm plugin.

  1. Add the npm module to the :npm :dependencies section of project.clj:
 :npm {:package {:scripts {:build "webpack -p"}}
       :dependencies [[react "16.4.0"]
                      [react-dom "16.4.0"]
                      ["@cljs-oss/module-deps" "1.1.1"]
Jul 26 14:02:01 ip-10-255-237-138 gaiad[12779]: I[07-26|14:02:01.352] HTTPRestRPC module=rpc-server method=/block args="[<*int64 Value>]" returns="[<*core_types.ResultBlock Value> <error Value>]"
Jul 26 14:02:01 ip-10-255-237-138 gaiad[12779]: I[07-26|14:02:01.352] Served RPC HTTP response module=rpc-server method=GET url="/block?height=0" status=200 duration=0 remoteAddr=127.0.0.1:57904
Jul 26 14:02:23 ip-10-255-237-138 gaiad[12779]: I[07-26|14:02:23.170] Ensure peers module=p2p numOutPeers=0 numInPeers=0 numDialing=0 numToDial=10
Jul 26 14:02:23 ip-10-255-237-138 gaiad[12779]: I[07-26|14:02:23.170] No addresses to dial nor connected peers. Falling back to seeds module=p2p
Jul 26 14:02:23 ip-10-255-237-138 gaiad[12779]: I[07-26|14:02:23.173] Dialing peer module=p2p address=5922bf29b48a18c2300b85cc53f424fce23927ab@67.207.73.206:26656
Jul 26 14:02:23 ip-10-255-237-138 gaiad[12779]: E[07-26|14:02
@pbostrom
pbostrom / README.md
Last active February 12, 2019 20:15
Livepeer
Livepeer node

The only things needed to run a Livepeer broadcasting node is the livepeer binary and an Ethereum keystore with passphrase. Copy the keystore to ~/.lpData/keystore and start the node with:

$ livepeer -ethPassword "passphrase" -ethUrl ws://<mainnet RPC server>:8546 -rtmpAddr 0.0.0.0:1935 -httpAddr 0.0.0.0:8935

This will create an RTMP endpoint on port 1935, which will accept connections from live video streams. Additionally, an HLS endpoint on port 8935 is used for streaming transcoded video to connecting players. You will need to deposit funds into your Livepeer account to pay transcoding fees. Use the Livepeer explorer and MetaMask to make a deposit using the same Ethereum account as above: https://explorer.livepeer.org/accounts//broadcasting. Once you have some funds you will need to configure the broadcasting node using the livepeer_cli command to set your maximum broadcasting fees and your desired tran

@pbostrom
pbostrom / missed.sh
Last active February 22, 2019 02:53
block_age() {
bt=$(date -d "$1" +%s)
now=$(date +%s)
echo $(( $now - $bt ))
}
status=$(curl -s http://localhost:46657/status)
addr=$(echo $status | jq -r ".result.validator_info.address")
lbh=$(echo $status | jq -r ".result.sync_info.latest_block_height")