Skip to content

Instantly share code, notes, and snippets.

(ns example.core
(:require [serialport :as comPort]) ;; As a side note, why does the :as clause add a second call to goog.require??
)
(def com (js.require "serialport")) ;; Using a dot instead of a / works incidentally
(def device-wrong1 (com.SerialPort. "COM1"))
(def SerialPort (.-SerialPort com))
(def device-correct1 (SerialPort. "COM1")) ;; Must I resort to this...
(ns example.core)
(def com (js.require "serialport")) ;; Using a dot instead of a / works incidentally
(def device-wrong3 (new com.SerialPort "COM1"))
;; // Compiled by ClojureScript 0.0-2080
;; goog.provide('example.core');
;; goog.require('cljs.core');
;; In Clojure
(update-in {:a 1 :b false} [:b] not)
;; => {:a 1, :b true}
(update-in {:a 1 :b false} [b] not)
;; => CompilerException java.lang.RuntimeException: Unable to resolve symbol: b in this context, compiling:(NO_SOURCE_PATH:1:1)
;; In ClojureScript
(update-in {:a 1 :b false} [b] not)
;;=> {:a 1, :b false, nil true}
;; WARNING: Use of undeclared Var example.core/b
// <label for={this.props.label}>{this.props.label}</label>
// compiles to...
React.DOM.label( {for:this.props.label}, this.props.label)
// should be...
React.DOM.label( {"for":this.props.label}, this.props.label)
// Because IE doesn't allow language keywords to appear unquoted in object literal keys
@aymanosman
aymanosman / nginx_auto_start.sh
Created August 1, 2014 12:11
Nginx: Start nginx on boot on Mac
# brew install nginx
sudo ln -s /usr/local/opt/nginx/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/
sudo chown root:wheel /usr/local/opt/nginx/homebrew.mxcl.nginx.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
# Why do you need sudo?
# If you want nginx to be able to bind to port 80, it will need superuser privileges
@aymanosman
aymanosman / fizzbuzz.hs
Last active August 29, 2015 14:09
fizzbuzz.hs
import Data.Maybe
import Data.Monoid
import Control.Applicative
-- Mostly stolen from an answer found posted on reddit.
-- This formulation achieves a high level of modularity and clarity.
-- It is modular with respect to adding more numbers to fizz and buzz against,
-- and captures the idea of `show`ing the number by default elegantly.
t m s n = if mod n m == 0 then Just s else Nothing
-- instance Applicative ((->) a) where (<*>) f g x = f x (g x)
@aymanosman
aymanosman / install_zmq.sh
Last active August 29, 2015 14:11
Install zeromq
#install zeromq
wget http://download.zeromq.org/zeromq-4.0.5.tar.gz
tar -xzf zeromq-4.0.5.tar.gz
cd zeromq-4.0.5
./configure
make
sudo make install
@aymanosman
aymanosman / challenges.md
Last active November 15, 2016 20:20
Challenges

Sum

sum1(1, 2, 3) == 6

Fizzbuzz

1 1
2 2
3 Fizz

4 4

@aymanosman
aymanosman / fz.py
Last active August 29, 2015 14:17
fz.py
def fizz(n):
for i in xrange(1, n+1):
print i, fz(i)
def t(m, s, n):
return s if (n%m==0) else ''
def fz(n):
s = ''.join([
t(3, 'Fizz', n),
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh