Skip to content

Instantly share code, notes, and snippets.

; Ported from https://www.autohotkey.com/board/topic/1257-half-qwerty-one-handed-typing/
; Many thanks to Chris for helping me out with this script.
mirror_1 = 0
mirror_2 = 9
mirror_3 = 8
mirror_4 = 7
mirror_5 = 6
mirror_q = p
mirror_w = o
class Recipe < ApplicationRecord
belongs_to :user
end
class User < ApplicationRecord
end
@kinopyo
kinopyo / Gemfile
Last active December 28, 2018 00:23
Make Turbolinks work with DoubleClick for Publishers(alternative of Google Adsense)
gem 'turbolinks'
gem 'jquery-turbolinks'

CSS

abbr expanded
m50 margin: 50px
p20 padding: 20px
m50-20 margin: 50px 20px
m0-auto margin: 0 auto
w20 width: 20px
w20p width: 20%
@kinopyo
kinopyo / gist:5682347
Last active March 21, 2018 05:12
Ruby: to_s vs. to_str

Concept

(The blockquote style does not look so well so I just pasted directly, but these are all quoted from the links in the bottom of this page)

You should not implement to_str unless your object acts like a string, rather than just having a string representation. The only core class that implements to_str is String itself.

[to_i and to_s] are not particularly strict: if an object has some kind of decent representation as a string, for example, it will probably have a to_s method… [to_int and to_str] are strict conversion functions: you implement them only if you object can naturally be used every place a string or an integer could be used.

to_str is used by methods such as String#concat to convert their arguments to a string. Unlike to_s, which is supported by almost all classes, to_str is normally implemented only by those classes that act like strings. Of the built-in classes, only Exception and String implement to_str

%span.css3_loader<
  %figure>
  %figure>
  %figure>
  %figure>
  %figure>
@kinopyo
kinopyo / gist:5355179
Last active December 16, 2015 01:29
memo on DestroyAllSoftware screencasts - override Struct initialize - alias_method :allow_export?, :allow_export
class Subscription < Struct.new(:id, :type)
attr_reader :allow_export
alias_method :allow_export?, :allow_export
def initialize(id, type)
super
@allow_export = id.present? && type == 'business'
end
end
@kinopyo
kinopyo / gist:5088737
Last active December 14, 2015 12:48
Notes: how to setup user based subdomain, http://stackoverflow.com/a/7265381/219065
module AppName
class UserSubdomainConstraint
def self.matches?( request )
request.subdomain.present? && request.subdomain != 'www'
end
end
end
AppName::Application.routes.draw do
devise_for :users
class Customer...
private TemporalCollection addresses = new SingleTemporalCollection();
public Address getAddress(MfDate date) {
return (Address) addresses.get(date);
}
public Address getAddress() {
return getAddress(MfDate.today());
}
public void putAddress(MfDate date, Address value) {
addresses.put(date, value);
@kinopyo
kinopyo / gist:3806238
Created September 30, 2012 08:19
Javascript shuffle array.
Array.prototype.shuffle = function() {
var len = this.length;
var i = len;
while (i--) {
var p = parseInt(Math.random()*len);
var t = this[i];
this[i] = this[p];
this[p] = t;
}
};