Skip to content

Instantly share code, notes, and snippets.

@kblake
kblake / postsql.sql
Created May 17, 2012 19:52 — forked from tobyhede/postsql.sql
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- JSON Types need to be mapped into corresponding PG types
--
-- Number => INT or DOUBLE PRECISION
-- String => TEXT
@kblake
kblake / gitbashprompt.txt
Last active July 2, 2018 21:13
Git bash prompt
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo "*"
}
function parse_git_stash {
[[ $(git stash list 2> /dev/null | tail -n1) != "" ]] && echo "^"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)$(parse_git_stash)/"
}
PS1='kman:> \W \[\e[0;36m\]$(parse_git_branch)\[\e[m\] $ '
#RUBYISMS
a = b.foo
if a.empty?
a = b.bar
else
a.reverse!
end
#can be simplied a little by assigning and
@kblake
kblake / phpresources.md
Created May 31, 2017 18:15
PHP: on-boarding new developer

PHP: on-boarding new developer

  • "Are you asking what tools we'd recommend? I love PhpStorm and HeidiSQL"
  • "If the newbie has experience with a few other languages, he/she should be able to pick up PHP on the fly. As such, I would have him/her read all of the documentation for the framework your team uses, i.e. Laravel, Symphony, etc. Reading through these framework docs will not only give the newbie an idea of PHP's syntax, but also a head start on understanding how your framework functions. There are so many good articles and videos on Laravel, for example. and I would be remiss if I didn't mention the PSR documentation at php-fig.org."
  • "Honestly the documentation for Laravel is so good that I would seriously consider starting there."
  • "If they have no php and minimal development background: https://www.amazon.com/Wicked-Cool-PHP-Real-World-Difficult/dp/1593271735"
  • "It's not modern but it's a quick, results oriented way to get moving. After they have some basis they can move into small projects
@kblake
kblake / devcoop_meetup_outline.md
Last active February 18, 2017 21:05
Outline for Dev Coop meetup (June 29th, 2016)
@kblake
kblake / short_circuit.ex
Last active November 30, 2016 08:41
Thought experiment where I want to short circuit the processing of a list of operations if one of them fails.
defmodule ExpensiveOperationWorker do
# recursion and pattern matching
def process([head | tail]) do
operation_passed?(head) && process(tail)
end
def process([]), do: true
# Enum.reduce_while
def process_operations(operations) do
Enum.reduce_while(operations, true, fn number, acc ->
defmodule ChatClient do
@server_name :chat_server
def hello do
IO.puts "hello world!!!"
end
def join_server server_id, cookie \\ :"cookiemonster" do
Node.set_cookie(Node.self, cookie)
pid = spawn(__MODULE__, :message_listener, [])
@kblake
kblake / amrita_sample_app.ex
Last active December 19, 2015 06:49
Amrita + Elixir setup and files
# Erlang R16B
# Elixir 0.9.3
# amrita 0.1.3
# mix.exs #####################################
defmodule AmritaSandbox.Mixfile do
use Mix.Project
def project do
[ app: :amrita_sandbox,