Skip to content

Instantly share code, notes, and snippets.

View kudosqujo's full-sized avatar

qujo kudosqujo

View GitHub Profile
@kudosqujo
kudosqujo / rm_whitespace_retab.sh
Created September 24, 2019 19:33
Remove trailing whitespace / retab directory of files (recursively)
Resources:
- https://superuser.com/questions/39040/re-indent-shell-script
- https://unix.stackexchange.com/questions/12902/how-to-run-find-exec
- https://superuser.com/questions/336016/invoking-vi-through-find-xargs-breaks-my-terminal-why
find ./path/to/dir -type f -name '*.rb' \
-exec vim -c 'set tabstop=2 shiftwidth=2 | retab | +normal gg=GZZ | %s/\s\+$//e | wq' {} \;
@kudosqujo
kudosqujo / mix_deps_get_and_compile.sh
Last active October 22, 2019 18:54
Get and Compile Mix dependencies #mix #elixir
mix run deps.get, compile
@kudosqujo
kudosqujo / install_sinatra.sh
Last active October 22, 2019 18:54
Install Sinatra w/o Documentation (as that may take extra time) #sinatra
$ gem install sinatra --no-rdoc --no-ri
@kudosqujo
kudosqujo / generate_method.rb
Last active April 9, 2020 00:34
[instance_eval and Procs] Using instance_eval and code blocks
# Will experience a performance benefit over #instance_eval as
# this method will experience only 1 scope change whereas with
# #instance_eval, that will happen for each request
def generate_method(method_name, &block)
method_name = method_name.to_sym
define_method(method_name, &block)
# grab the unbound method block
method = instance_method method_name
remove_method method_name
method
@kudosqujo
kudosqujo / run_rack_app.sh
Last active April 8, 2020 21:29
[Run Rack App] #rack
rackup -p 4567
# Must be called in same directory as config.ru
# -s thin specifies to run w/ thin server
rackup -p 4567 -s thin
@kudosqujo
kudosqujo / sinatra_class_inheritance.rb
Last active April 8, 2020 21:28
[Sinatra Class Inheritance] #sinatra
require 'sinatra/base'
class MyApp < Sinatra::Base; end
class SubApp < MyApp; end
MyApp.set :string, "Hi"
MyApp.string #=> "Hi"
SubApp.string #=> "Hi"
SubApp.set :string, "Hello"
SubApp.string #=> "Hello"
MyApp.string #=> "Hi"
@kudosqujo
kudosqujo / list_directories_only.sh
Last active April 8, 2020 21:26
List directories only
ls -l | grep ^d
@kudosqujo
kudosqujo / Directives.md
Last active April 8, 2020 21:27
[GraphQL Terms] examples of directives, variables, fragments, and inline fragments #graphql
query Hero($episode: Episode, $withFriends: Boolean!) {
  hero(episode: $episode) {
    name
    friends @include(if: $withFriends) {
      name
    }
  }
}
@kudosqujo
kudosqujo / undo_dropped_commit.sh
Created January 2, 2020 20:07
Undo a dropped commit #git
# Find the SHA of the dropped commit
gitk --all --date-order $(git log -g --pretty=%H)
# Once you have found the correct state of your branch, you can get back to that state by running
git reset --hard SHA
# You could also link that old state to a new branch name using
git checkout -b newbranch SHA
@kudosqujo
kudosqujo / define_hash_tables_in_bash3.bash
Last active April 9, 2020 00:39
Define Hash Tables in Bash #bash
#!/usr/bin/env bash
# Assumes you are running with Bash 3
# {see: https://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash}
# First, indirection.
animals_moo=cow; sound=moo; i="animals_$sound"; echo "${!i}"
# Secondly, `declare`:
sound=moo; animal=cow; declare "animals_$sound=$animal"; echo "$animals_moo