Skip to content

Instantly share code, notes, and snippets.

View shimx's full-sized avatar

shimx shimx

View GitHub Profile
@shimx
shimx / file0.txt
Last active October 5, 2018 06:52
Rails4におけるブラウザプッシュ通知(Web Push Notifications)実装 ref: https://qiita.com/shimx/items/d23bb45b34c89f879db3
{
"name": "WEB APP NAME",
"short_name": "WEB APP",
"start_url": "/"
}
@shimx
shimx / image_dimensions_validator.rb
Last active November 9, 2016 05:45
Paperclip で保存する画像の寸法チェックをする ref: http://qiita.com/shimx/items/ff69afa83075d6ef61cf
class ImageDimensionsValidator < ActiveModel::EachValidator
CHECKS = { greater_than: :>, greater_than_or_equal_to: :>=,
equal_to: :==, less_than: :<, less_than_or_equal_to: :<= }.freeze
SIDES = [:width, :height].freeze
def validate_each(record, attribute, value)
dimensions = Paperclip::Geometry.from_file(value.queued_for_write[:original].path)
SIDES.each do |side|
@shimx
shimx / kiyoshi.pl
Last active March 11, 2016 13:04
ズンドコキヨシ with Perl ref: http://qiita.com/shimx/items/51da4b56bca1ac2cb269
use strict;
use warnings;
sub kiyoshi {
my @zd = my ($z, $d) = ('ズン', 'ドコ');
my $str = join('', (my @kys = ($z, $z, $z, $z, $d)));
my $cnt = 0;
my @word;
while ( join('', @word) ne $str ) {
@shimx
shimx / perl-girlfriends
Last active December 31, 2015 12:24
MacのターミナルにPerlで彼女を降らせる
perl -e 'chomp($c=scalar(`stty size`));$c=int(${[split(/\s/, $c)]}[1]);$s=pack("H*","e5bdbce5a5b3");print "\e[2J";while(1){$a{rand $c}=0;for $x (keys %a){$y=$a{$x}++;print sprintf("\e[%d;%dH \e[%d;%dH \e[%d;%dH \e[%d;%dH%s \e[0;0H",$y,$x,$y,$x+1,$y,$x+2,$a{$x},$x,$s)}local $|=1;select $u,$u,$u,0.2}'
@shimx
shimx / girlfriends
Created June 24, 2014 14:56
Macのターミナルに彼女を降らせる
$ ruby -e 'C=`stty size`.scan(/\d+/)[1].to_i;S="\u5f7c\u5973";a={};puts "\033[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"};$stdout.flush;sleep 0.1}'