Skip to content

Instantly share code, notes, and snippets.

@hadees
hadees / arel_helpers.rb
Created March 5, 2016 05:41
Arel Helpers
module ArelHelpers
extend self
def self.included(base)
base.extend self
end
def asterisk(arel_table_or_model)
arel_table, columns = case arel_table_or_model
when Arel::Table
en:
letter_closings:
- Adios
- All best wishes
- All best, always
- Always in my thoughts
- As always, with affection
- Be good
- Be well
- Best Regards
@hadees
hadees / js
Last active November 10, 2018 23:51
// Run on https://www.youtube.com/user/foobar/playlists?view=1&shelf_id=0&sort=dd
function getParents(el, parentSelector /* optional */) {
// If no parentSelector defined will bubble up all the way to *document*
if (parentSelector === undefined) {
parentSelector = document;
}
var parents = [];

Validate JSON schema in Rails

Topics

  1. What/Why JSON schema
  2. Apply to rails model validation
  3. Test your API endpoint with schema matcher
  4. Homework for a curious reader
  5. References
pragma solidity ^0.4.20;
interface FoodSafety {
function owner
function transfer
function split

Keybase proof

I hereby claim:

  • I am hadees on github.
  • I am hadees (https://keybase.io/hadees) on keybase.
  • I have a public key whose fingerprint is A0C1 850A 15D1 1F77 DA03 94F3 367E 21AD A895 8278

To claim this, I am signing this object:

class BooleanValue
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/column.rb#L8
FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"]
def self.convert(value)
Rails.present? ? with_rails(value) : without_rails(value)
end
private
@hadees
hadees / model.rb
Created September 20, 2016 01:44
Model Template
<% module_namespacing do -%>
class <%= class_name %> < <%= parent_class_name.classify %>
### Default Scope
### Includes and Extensions
### Constants
### Virtual attributes
$ youtube-dl --autonumber-size 3 --restrict-filenames -o "S01E%(autonumber)s-%(title)s.%(ext)s" --playlist-reverse https://www.youtube.com/playlist?list=PLE7j5FieXSTc-2gbs7NkrDPhkS_rQS9XT
$(document).ready(function() {
if(window.self !== window.top) {
var padding = 200;
var currentHeight = window.ApplicationHelpers.pageHeight() + padding;
var resizeIframeTracker = setInterval(function() {
$(document).ready(function() {
var height = window.ApplicationHelpers.pageHeight() + padding;
if(currentHeight !== height) {
message = JSON.stringify({"frameHeight": height});
window.parent.postMessage(message, "*");