Skip to content

Instantly share code, notes, and snippets.

@knoxknox
knoxknox / ff
Last active April 20, 2020 11:17
#!/bin/bash
##
# Interactive search.
# Usage: `ff` or `ff <folder>`.
#
[[ -n $1 ]] && cd $1 # go to provided folder or noop
RG_DEFAULT_COMMAND="rg -i -l --hidden --no-ignore-vcs"
selected=$(
@knoxknox
knoxknox / th
Last active December 29, 2019 23:23
##
# MySQL 8 CTE
# tree (id int, pid int, name varchar(255))
#
WITH recursive tbl AS (
SELECT
t.id,
1 AS depth,
cast(name as CHAR(500)) AS path
FROM tree t WHERE t.pid IS NULL
// create a mutable set
Set<String> set = Sets.newHashSet("Jay", "Betsy");
// create an immutable set
Set<String> set = ImmutableSet.of("Jay", "Betsy", "Jenny");
// create a mutable list
List<String> list = Lists.newArrayList("Jay", "Betsy");
// create an immutable list
List<String> list = ImmutableList.of("Jay", "Betsy", "Jenny");
##
# cap rails:console
# https://gist.github.com/benedikt/1115513#comment-576015
#
namespace :rails do
desc "Remote console"
task :console, roles: :app do
run_interactively "bundle exec rails console #{rails_env}"
end
end
- Set theory [https://en.wikipedia.org/wiki/Set_theory]
- Graph theory [https://en.wikipedia.org/wiki/Graph_theory]
- Number theory [https://en.wikipedia.org/wiki/Number_theory]
- Combinatorics [https://en.wikipedia.org/wiki/Combinatorics]
- Linear algebra [https://en.wikipedia.org/wiki/Linear_algebra]
- Relational algebra [https://en.wikipedia.org/wiki/Relational_algebra]
# controllers/application_controller.rb
class ApplicationController
# @override
def current_ability
@current_ability ||= Ability::Factory.build(user)
end
end
# ability/factory.rb
class Ability::Factory
##
# Hooks:
# extended (Class that called with extend)
# included (Class that called with include)
# prepended (Class that called with prepend)
# inherited (Class that was inherited with <)
# method_added (Method symbol of new method created)
# method_removed (Method symbol when method removed)
# method_undefined (Method symbol of undefined method)
# singleton_method_added (Method symbol of new method created)
# syntax
can(action, object_class)
# ability.rb
can(:custom_ability, Person)
can(:controller_action, Person)
cannot(:read, Feedback) { |model| true }
# persons_controller.rb
def action