A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.
posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <style> | |
| .editor { font-family: 'Roboto Mono', monospace; font-size: 12px; outline: none; overflow-y: auto; padding-left: 48px; counter-reset: line; } | |
| .editor div { display: block; position: relative; white-space: pre-wrap; } | |
| .editor div::before { content: counter(line); counter-increment: line; position: absolute; right: calc(100% + 16px); opacity: 0.5; } | |
| </style> | |
| </head> |
| require 'rails_helper' | |
| RSpec.describe TodosController, :type => :controller do | |
| describe "GET #index" do | |
| #describe "POST #create" do | |
| #describe "GET #show" do | |
| #describe "PATCH #update" do (or PUT #update) | |
| #describe "DELETE #destroy" do | |
| #describe "GET #new" do |
dhcp-script=/etc/detect_new_device.sh
Reference:
| module InterruptibleSleep | |
| def interruptible_sleep(seconds) | |
| @_sleep_check, @_sleep_interrupt = IO.pipe | |
| IO.select([@_sleep_check], nil, nil, seconds) | |
| end | |
| def interrupt_sleep | |
| @_sleep_interrupt.close if @_sleep_interrupt | |
| end | |
| end |
| # Shamelessly stolen from https://gist.github.com/ileitch/1459987 | |
| module InterruptibleSleep | |
| def interruptible_sleep(seconds) | |
| @sleep_check, @sleep_interrupt = IO.pipe | |
| IO.select([@sleep_check], nil, nil, seconds) | |
| end | |
| def interrupt_sleep | |
| @sleep_interrupt.close if @sleep_interrupt |
| require 'RMagick' | |
| TOP_N = 10 # Number of swatches | |
| # Create a 1-row image that has a column for every color in the quantized | |
| # image. The columns are sorted decreasing frequency of appearance in the | |
| # quantized image. | |
| def sort_by_decreasing_frequency(img) | |
| hist = img.color_histogram | |
| # sort by decreasing frequency |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script> | |
| <script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js"></script> | |
| <style type="text/css"> | |
| rect { | |
| fill: none; | |
| stroke: #fff; |