Skip to content

Instantly share code, notes, and snippets.

@joonyou
joonyou / markdown10.css
Created March 13, 2019 05:57
markdown css
body {
font: 16px 'Open Sans', sans-serif;
color:black;
line-height:1.2em;
background-color: #FFFFFF;
padding: 0.7em;
}
p {
margin:1em 0 1em 1.2em;
line-height:1.5em;
@joonyou
joonyou / polymorphic example
Last active July 19, 2018 13:41
ActiveRecord Polymorphic
%w(rspec active_record sqlite3 pry-byebug).each {|gem| require gem }
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:' )
class CreateTestDB < ActiveRecord::Migration[5.2]
def self.up
create_table :foos do |t|
t.string :name
AllCops:
TargetRubyVersion: 2.2
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'
kylo [2.4.1] [~] ➜ cat bin/newrailsapp.sh
#!/bin/bash
set -e
app=$1
approot=$HOME/box/$1
# create a new rails app with my usuals
cd $HOME/box
@joonyou
joonyou / rspec_deprecated.rb
Created September 3, 2013 04:50
deprecated rspec stub
class Foo
def repeat
2.times { repeated }
end
def repeated; end
end
describe Foo do
let(:foo) { stub method1:"hello" }
@joonyou
joonyou / visitor pattern demo
Created August 13, 2013 18:11
code from visitor pattern screencast
class Goodie
attr_accessor :price
def initialize(price)
@price = price
end
def accept(visitor)
visitor.visit(self)
end
@joonyou
joonyou / Ruby 2.0 – Getting Started & Named Parameters
Created February 24, 2013 20:34
Ruby 2.0 – Getting Started & Named Parameters
def foo(with:"default", delegate:String, selector:"to_s")
puts "with: #{with}"
puts "delegate: #{delegate.class.to_s}"
puts "result: #{delegate.send(selector)}"
end
def bar; puts "hello from Bar";end
foo with:"Joon", delegate:self, selector:"bar"
@joonyou
joonyou / calling method
Created November 2, 2010 23:07
calling method
require 'rspec'
class Victim
def called_name
caller_name = caller[0].scan(/\`.*\'/).first.gsub(/\`|\'/,"") rescue "outside of self"
if caller_name =="my_caller"
"looks like it's called from my_caller"
else
"who's calling me? #{caller_name} is"
end
@joonyou
joonyou / redis startup
Created September 22, 2010 12:53
redis startup
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
#!/usr/bin/env ruby
#
if $*.size < 1
puts "usage: rename \"{file search criteria}\" pattern replacement"
puts "example: rename \"*\" .MOV .mov"
puts " this changes the .MOV to .mov in all files in current directory"
else
files = Dir.glob "#{$*[0]}"
files.each do |f|