Skip to content

Instantly share code, notes, and snippets.

View daveshah's full-sized avatar
💭
💻

Dave Shah daveshah

💭
💻
View GitHub Profile
@daveshah
daveshah / tmux-cheatsheet.markdown
Created January 31, 2017 15:27 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@daveshah
daveshah / spacemacs_hint.md
Created January 26, 2017 16:52 — forked from ivar/spacemacs global search and replace.md
spacemacs - global search and replace

There's a couple of ways, one way is

  • Get search results
    • Do SPC / and type in your search string
    • or SPC x S and search string - where x is your scope indicator (p for project, d for directory, etc..)
  • Once you have the occurences you want, hit C-c C-e inside the helm buffer to put all your match occurences and puts them into a special buffer called the edit buffer or something like that
  • in that buffer you can use any commands you'd normally use on a buffer
  • the C-c C-c to commit your changes.
@daveshah
daveshah / solid_elixir.md
Last active August 31, 2016 13:05
CodeMash Abstracts

S.O.L.I.D. Elixir

S.O.L.I.D. - for roughly a decade, many have learned and sought to apply these principles in the context of
Object Oriented Programming. As Functional languages like Elixir become more mainstream, one might wonder if these concepts are still applicable and, if so, seek out concrete examples that demonstrate their merit in this new functional world. Come prepared to tour each of the S.O.L.I.D. design principles and to examine how S.O.L.I.D. principles not only apply to Object Oriented Programming, but also to Functional Programming in Elixir.

@daveshah
daveshah / middleware_spec.rb
Created July 19, 2016 18:57
Testing middleware
require 'rails_helper'
describe Rack::MyMiddleware do
let(:app) { proc { [200, {}, ['Hello Dave']] } }
let(:stack) { described_class.new(app) }
let(:request) { Rack::MockRequest.new(stack) }
context 'A POST request' do
#NOTE TIL = this is how I post all the things
@daveshah
daveshah / til.ex
Last active July 6, 2016 17:19
TIL: Ecto 2.0 many_to_many
# 1) Created User and Run models first (generated)
# 2) Created the UserRun model (generated) then removed all but Ecto.Schema
# 3) Corrected the UserRun model so that it looked like this:
defmodule Gatherto.UserRun do
use Ecto.Schema
schema "users_runs" do
belongs_to :user, Gatherto.User #this was VERY important! Before I had field :user_id, :binary_id
belongs_to :run, Gatherto.Run #this was VERY important! Before I had field :run_id, :binary_id
timestamps()
@daveshah
daveshah / delete_all_bak.sh
Created May 27, 2016 09:25
delete all .bak files
find . -name "*.bak" -type f -delete
@daveshah
daveshah / replace.sh
Created May 27, 2016 09:22 — forked from hlissner/replace.sh
Bulk search & replace with ag (the_silver_searcher)
# ag <https://github.com/ggreer/the_silver_searcher>
# usage: ag-replace.sh [search] [replace]
# caveats: will choke if either arguments contain a forward slash
# notes: will back up changed files to *.bak files
ag -l $1 | xargs perl -pi.bak -e "s/$1/$2/g"
# or if you prefer sed's regex syntax:
ag -l $1 | xargs sed -ri.bak -e "s/$1/$2/g"
Go buy a Mac ;)
@daveshah
daveshah / weird.ex
Created May 13, 2016 14:12
Parsing lolz
iex(11)> foo_int = "123foobar"
"123foobar"
iex(12)> String.to_integer(foo_int)
** (ArgumentError) argument error
:erlang.binary_to_integer("123foobar")
iex(12)> Integer.parse(foo_int)
{123, "foobar"}
@daveshah
daveshah / output
Created May 13, 2016 12:03
I prefer the latter to the former... :)
Assertion with == failed
code: Words.count("co-operative") == expected
lhs: %{"co" => 1, "operative" => 1}
rhs: %{"co-operative" => 1}
Assertion with == failed
code: Words.count("co-operative") == %{"co-operative" => 1}
lhs: %{"co" => 1, "operative" => 1}
rhs: %{"co-operative" => 1}