Creates a clojure script that listens on TCP port 8000 and prints out lines received through the connection.
(require '[clojure.java.io :as io])
(import '[java.net ServerSocket])
(defn receive
"Read a sequence of lines from the socket"
I recently worked on a project where I needed to pull in a reasonably sized data set only to filter away a large majority of it. Needless to say the memory implications for scaling this up were concerning. So here's a quick demo of a problem where we want to pull in a list of all the words that start with "B" from a dictionary. The two methods are 1) the original pull in the dictionary then filter down to the "B"'s and 2) filter the data on ingress. Option 2)'s maximum memory consumption is approximately 6% of option 1.
library(pryr)
DICTIONARY <- '/etc/dictionaries-common/words'
sudo tcpdump -s 0 -A -i lo0 'tcp port 8080 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' |
wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.0-2_amd64.deb
sudo dpkg -i chefdk_0.2.0-2_amd64.deb
mkdir -p ~/.chefdk
echo 'eval "$(chef shell-init bash)"' >> ~/.bashrc
echo 'export PATH="/opt/chefdk/embedded/bin:${HOME}/.chefdk/gem/ruby/2.1.0/bin:$PATH"' >> ~/.bashrc
wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.3_x86_64.deb
sudo dpkg -i vagrant_1.6.3_x86_64.deb
# Add this function to your ~/.bashrc file to allow you to jump to the top of a complex dir tree | |
# | |
# Examples: | |
# user@host:~/git_stuff/git_repo1/dir1/subdir/subsubdir $ cdr | |
# user@host:~/git_stuff/git_repo1 $ | |
# | |
# user@host:~/svn_stuff/svn_repo1/dir1/subdir/subsubdir $ cdr | |
# user@host:~/svn_stuff/svn_repo1 $ | |
# | |
# user@host:~/just/a/normal/dir/structure $ cdr |
duration_1 = 0; | |
duration_2 = 0; | |
iter = 100000; | |
for i=1:iter | |
if mod(i,2) == 0 | |
tic; | |
a = now(); | |
duration_1 = duration_1 + toc; | |
else | |
tic; |