Skip to content

Instantly share code, notes, and snippets.

@manutter51
manutter51 / lazy-outer-inner-seq.clj
Last active October 25, 2018 13:45
Hand-rolled lazy seq for pairing inner values to outer keys in a map nested 1 layer deep with other maps.
(def mm {1 {101 :a 102 :b 103 :c} 2 {201 :aa 202 :bb}})
;; possible cases
;; fully populated {1 {11 :a, 12 :b}, 2 {21 :a, 22 :b}}
;; single inner value {1 {12 :b}, 2 {21 :a, 22 b}}
;; empty inner value, multi-entry outer {1 {}, 2 {21 :a, 22 :b}}
;; other degenerate cases that boil down to either "the first key-value pair has data to process" or "We're done."
(defn outer-inners
@manutter51
manutter51 / RsyncUpload
Last active August 29, 2015 13:56
Rsync upload with delete
rsync -azP --delete --exclude-from=.gitignore <src> <dest>
@manutter51
manutter51 / snippets.sh
Created July 29, 2013 17:48
bash snippets
#!/bin/bash
alias reload="source ~/.bashrc"
# source the sublimerc file if it exists
if [ -f "${HOME}/.sublimerc" ] ; then
source "${HOME}/.sublimerc"
fi
src()
@manutter51
manutter51 / MyList.ex
Created July 26, 2013 16:58
Decided to do one of the exercises from _Programming Elixir_, section 7.5. "Write max(list) that returns the element with the maximum value in the list (This is slightly trickier than it sounds.)" I've got both the max value and the (1-based) index of the max value. My First Elixir Code (aw)!
defmodule MyList do
def mymax([h | t]), do: mymax(h, t)
def mymax(v, []), do: v
def mymax(v, [h | t]) when h < v, do: mymax(v, t)
def mymax(_v, [h | t]), do: mymax(h, t)
@manutter51
manutter51 / gist:6066118
Last active December 20, 2015 03:49
If you make multiple syntax errors in a row, iex repeats the error output of the first mistake for the second and following errors.
Erlang R16B01 (erts-5.10.2) [source-bdf5300] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (0.10.1-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 1 + 3
4
...
iex(5)> a = "foo"
"foo"
iex(6)> 8 + a
** (ArithmeticError) bad argument in arithmetic expression
@manutter51
manutter51 / auth.clj
Created July 21, 2013 23:20
The right way.
;; ...
(defn- lock [handler]
(friend/requires-scheme handler :https {:http 3333
:https 3334}))
(defroutes sensitive-routes
(GET "/register" []
(layout/render "auth/register.html"))
@manutter51
manutter51 / localhost
Last active December 20, 2015 01:28
Local nginx config for using http-kit with and without SSL
upstream http_backend {
server localhost:33333;
keepalive 32;
}
server {
listen 3333 default_server;
server_name localhost;
@manutter51
manutter51 / auth.clj
Last active December 20, 2015 01:19
Restricting access for sensitive pages.
(ns share-for-all.routes.auth
;; ...
(:require ;; ...
[cemerick.friend :as friend]
(cemerick.friend [workflows :as workflows]
[credentials :as creds])))
;; ...
(defroutes secured-routes
(GET "/register" req
@manutter51
manutter51 / sql2ent.rb
Last active December 18, 2015 05:49
Ruby script to generate rudimentary Doctrine 2 Entity files from SQL "CREATE TABLE" queries.
#!/Users/mnutter/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
def toCamel(s)
while s =~ /([^_]+)_(.)(.*)$/ do
s = $1 + $2.upcase + $3
end
return s
end
def toSnake(s)
@manutter51
manutter51 / Sublime Text 2.desktop
Created May 26, 2013 18:34
Linux/gnome desktop entry file. Put this file in ~/.local/share/applications/ to get Ubuntu desktop to use Sublime Text 2 as a well-known text editor. Note that I've hard coded my personal directory paths in the Exec and Icon lines, so edit this to suit your own situation.
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Name=Sublime Text 2
GenericName=Text Editor
Comment=View and edit files
Exec=/home/mark/SublimeText2/sublime_text %F
Icon=/home/mark/SublimeText2/Icon/128x128/sublime_text.png
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;text/x-clj;text/x-cljs