Skip to content

Instantly share code, notes, and snippets.

@nathan-appere
nathan-appere / copy-checklist.js
Last active May 8, 2020 — forked from niallsmart/copy-checklist.js
Copy Trello checklist to clipboard
View copy-checklist.js
copy($(".checklist-item:not(.checklist-item-checked)").map(function() {
var $el = $(this),
item = $el.find(".checklist-item-details-text").text();
if ($el.hasClass("checklist-item-state-complete")) {
item = "- [x] " + item;
} else {
item = "- [ ] " + item;
}
return item;
}).get().join("\n"));
View routes.txt
RAILS WAY FOR REFERENCE -------------------------------------------------------
@note This was designed "web client" first, not really good for APIs.
HTTP Verb Path Action Used for
GET /photos photos#index display a list of all photos
GET /photos/new photos#new return an HTML form for creating a new photo
POST /photos photos#create create a new photo
GET /photos/:id photos#show display a specific photo
GET /photos/:id/edit photos#edit return an HTML form for editing a photo
View database.yml
config_default: &config_default
adapter: <%= ENV['DATABASE_ADAPTER'] || 'postgresql' %>
encoding: utf8
pool: <%= (ENV['DATABASE_POOL'] || ENV['MAX_THREADS'] || 5) %>
# Readonly mode | expected privileges: [CONNECT, SELECT]
config_default_readonly: &config_default_readonly
<<: *config_default
url: <%= ENV['DATABASE_URL_READONLY'] %>
View contract-example.rb
module Test
module RGB
include Kit::Contract
before ->(r:, g:, b:) { (0..255) === r && (0..255) === g && (0..255) === b }
after [
->(result:) { result.is_a?(String) },
->(result:) { result.start_with?('#') },
->(result:) { result.length.in?([4, 7]) },
]
@nathan-appere
nathan-appere / kit-contracts.rb
Last active Oct 11, 2019
Example of ruby contracts
View kit-contracts.rb
module RGB
# First step -----------------------------------------------------------------
before ->(r:, g:, b:) { (0..255) === r && (0..255) === g && (0..255) === b }
after [
->(result:) { result.is_a?(String) },
->(result:) { result.start_with?('#') },
->(result:) { result.length.in?([4, 7]) },
]
@nathan-appere
nathan-appere / sig.rb
Created Oct 1, 2019 — forked from havenwood/sig.rb
An example for Nathanael7 on #ruby IRC
View sig.rb
def sig(method_name)
meth = method(method_name)
parameters = meth.parameters.map do |type, name|
case type
when :req
name
when :rest
"*#{name}"
when :opt
# Unknown default argument.
View dry-types.rb
require 'dry-types'
require 'pry'
module Types
include Dry.Types
end
ProtocolType = Types::Symbol.enum(:http, :async, :websockets)
HttpVerb = Types::Symbol.enum(:get, :post)
View pagination.txt
| D1 | D2 | D3
R1 | A | W | 0
R2 | A | W | 1
R3 | A | X | 2
R4 | A | X | 3
R5 | A | Y | 4
R6 | B | Y | 5
R7 | B | Z | 6
R8 | C | Z | 1
@nathan-appere
nathan-appere / organizer.rb
Last active Jul 21, 2019
Bare logic for a functional organizer
View organizer.rb
require 'contracts'
module Organizer
include Contracts
Contract KeywordArgs[list: ArrayOf[RespondTo[:call]], ctx: Optional[Hash]] => [Symbol, Hash]
def self.call(list:, ctx: {})
result = :ok
begin
You can’t perform that action at this time.