Skip to content

Instantly share code, notes, and snippets.

@markgarrigan
markgarrigan / object_blank_present.rb
Created May 21, 2012 16:42
Ruby blank? and present?
class Object
def blank?
respond_to?(:empty?) ? empty? : !self
end
def present?
!blank?
end
end
@markgarrigan
markgarrigan / square.tag
Last active January 15, 2019 04:58
The square component for riot tic tac toe.
<square>
<button onclick={opts.click}>{opts.val}</button>
<style>
:scope {
display: block;
background: #fff;
border: 1px solid #999;
float: left;
height: 34px;
@markgarrigan
markgarrigan / board.tag
Created January 15, 2019 04:53
The board component for riot tic tac toe.
<board>
<square each={square, i in opts.squares} click={() => parent.opts.click(i)} val={square} no-reorder></square>
<style>
:scope {
display: block;
width: calc(36px * 3);
}
.status {
margin-bottom: 10px;
@markgarrigan
markgarrigan / game.tag
Created January 15, 2019 04:54
The game component for riot tic tac toe.
<game>
<board squares={current.squares} click={handleClick}></board>
<div class="game-info">
<div>{ status }</div>
<ol if={moves}>
<li each={moves} key={move}>
<button onClick={() => jumpTo(move)}>{desc}</button>
</li>
</ol>
</div>
@markgarrigan
markgarrigan / Luhn.rb
Last active March 8, 2019 09:11
Luhn Validator
class Luhn
def self.valid?(string)
transformed = string.gsub(/ /,'') #Remove spaces
return false if transformed.length < 1 #Return false if length less than 1
return false if transformed.match?(/\D/) #Return false if any non digit characters
# Reverse the string Scan for 2 capture groups
transformed = transformed.reverse.scan(/(.)(.)/).each do |pair|
# Turn both items into integers
pair[0] = pair[0].to_i
pair[1] = pair[1].to_i
@markgarrigan
markgarrigan / app.riot
Last active February 26, 2020 16:34
Child directly nested in route. Riot.js v4
<app>
<h1>Hello</h1>
<router>
<ul>
<li>
<a href="/child">Child</a>
</li>
</ul>
<route path="/child">
<child something={ doSomething }></child>
@markgarrigan
markgarrigan / app.riot
Last active February 26, 2020 16:35
Route nested in child. Riot.js v4
<app>
<h1>Hello</h1>
<router>
<ul>
<li>
<a href="/child">Child</a>
</li>
</ul>
<child something={ doSomething }></child>
</router>
version: '2'
services:
base:
image: {{image}}
volumes:
- .:{{dir}}
- {{volume}}:{{dir}}/node_modules
working_dir: {{dir}}
init:
extends:
#!/bin/bash
PATH=./node_modules/.bin:$PATH
function dockup {
temp=${temp:-tmp}
builder="node.docker-compose.builder.tpl.yml"
compose="node.docker-compose.tpl.yml"
builderOut="docker-compose.builder.yml"
composeOut="docker-compose.yml"
image=${image:-node:12.16.2}
version: '3.7'
services:
nginx:
image: nginx:latest
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf:ro
ports:
- 80:80
{{name}}: