Skip to content

Instantly share code, notes, and snippets.

@briandunn
briandunn / tacobell.rb
Created December 13, 2018 20:17
read tacobell nutrition info from their web site
require 'open-uri'
require 'nokogiri'
doc = Nokogiri(URI('https://www.nutritionix.com/taco-bell/menu/premium').read)
headers = doc.css('thead th a span span[aria-hidden]').map do |header|
header.text.strip
end
rows = doc.css('tbody tr').map do |row|
@briandunn
briandunn / fk.rb
Last active October 25, 2018 19:00
list tables and columns of non-polymorphic foreign keys
ApplicationRecord.descendants.flat_map do |c|
c.reflect_on_all_associations.select do |a|
ActiveRecord::Reflection::BelongsToReflection === a && !a.options[:polymorphic]
end
end.map do |r|
[r.active_record.table_name, r.plural_name, r.options.slice(:optional, :foreign_key)]
end.uniq.sort
https://www.graphviz.org/
task graph: :environment do
result = ActiveRecord::Base.connection.execute <<~SQL
select source.relname as source, dest.relname as dest
from pg_catalog.pg_constraint as fk
join pg_catalog.pg_class as source on source.oid = fk.conrelid
join pg_catalog.pg_class as dest on dest.oid = fk.confrelid
where contype = 'f'::char
SQL
relations = result.map(&:symbolize_keys).reduce({}) do |h, source:, dest:|
@briandunn
briandunn / reagent-animated-example.cljs
Last active September 19, 2018 16:52 — forked from dvcrn/reagent-animated-example.cljs
reagent react-native animation example
;; very simple example on how to use Animated with reagent
;; https://facebook.github.io/react-native/docs/animations.html
(def animated (.-Animated js/React))
(def animated-value (.-Value animated))
(def animated-view (r/adapt-react-class (.-View animated)))
(defn bounce []
(let [bounce-value (new animated-value 0)]
(.setValue bounce-value 1.5)
live_loop :squiggle, sync: :drums do
#stop
s = synth :blade, note: :e, sustain: 1, slide: halves(0.5, 3).tick(:h), amp: 0.15
4.times do
sleep halves(1, 5).tick
control s, note: degree(range(1,7).tick(:b), :c3, :major),
pan: rand(2) - 1,
amp: 0.3
end
sleep vt.ceil - vt
@briandunn
briandunn / repl
Created July 8, 2015 15:35
cljs warnings
cljs.user=> (cljs.test/run-tests 'seqseq.test)
WARNING: Use of undeclared Var cljs.core/volatile! at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/concat at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/concat at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/concat at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/-vreset! at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/partial at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/merge-with at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/+ at line 1 <cljs repl>
WARNING: Use of undeclared Var cljs.core/-deref at line 1 <cljs repl>
# project Ardour3 (3.5.357) configured on Fri Apr 4 11:02:56 2014 by
# waf 1.6.11 (abi 98, python 20706f0 on darwin)
# using ./waf configure
#
----------------------------------------
Setting top to
/Users/brian/src/ardour
----------------------------------------
Setting out to
/Users/brian/src/ardour/build
def get_step_name(scenario)
if Cucumber::Ast::OutlineTable::ExampleRow === scenario
outline = scenario
return outline.backtrace_line
else
scenario.instance_variable_get :@current_step
visitor = scenario.instance_variable_get :@current_visitor
listeners = visitor.instance_variable_get :@listeners
formatter = listeners.first
step = formatter.instance_variable_get :@current_step
@briandunn
briandunn / QuickFix notes
Last active December 28, 2015 08:29
Notes on my QuickFix talk at VimChi
QuickFix
--------
Overview:
rational: Vim has a lot of great ways to navigate a project. But if your computer already knows where the problem is, we should be able to jump straight there without searching again.
:help quickfix
Supports "edit-compile-edit"
Inspired by an Amega compiler