Skip to content

Instantly share code, notes, and snippets.

@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\] $ '
@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 / 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 ->
@kblake
kblake / devcoop_meetup_outline.md
Last active February 18, 2017 21:05
Outline for Dev Coop meetup (June 29th, 2016)
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 / struct-pitfalls.txt
Created November 23, 2015 03:09
Struct Pitfalls
Read more here:
http://www.benjaminoakes.com/2013/10/15/superclass-mismatch-when-inheriting-from-struct-new/
http://thepugautomatic.com/2013/08/struct-inheritance-is-overused/
http://idiosyncratic-ruby.com/18-con-struct-attributes.html#why-not-structs-everywhere
https://twitter.com/joshsusser/status/365286610578849794
@kblake
kblake / histogram.rb
Created September 28, 2015 23:50
Histogram
test_scores = [88, 100, 93, 65, 89, 90, 78, 99, 54]
If given an array of integers, display a horizontal histogram using ‘*’
For example,
Produce:
88 : ****************************************************************************************
@kblake
kblake / gist:a99bf6b3c549780e7523
Created January 30, 2015 03:06
Cell server - Conway's Game of Life
IO.puts "Conway's Game of Life"
defmodule Cell do
def next_cycle do
receive do
{sender, number_live_neighbors} ->
cond do
number_live_neighbors < 2 ->
send sender, {:died, die_off}
number_live_neighbors > 3 ->