Skip to content

Instantly share code, notes, and snippets.

View data-mask.yml
inquiries:
mail_address: Faker::Internet.email
nickname: Faker::Games::Pokemon.name
message_body: Faker::Lorem.paragraph
View recursive_fizz_buz.rb
def fizz_buz(n)
return if n > 100
word = if n % 15 == 0
'fizz buz'
elsif n % 3 == 0
'fizz'
elsif n % 5 == 0
'buz'
end
puts word if word
View pretty_yaml
#!/usr/bin/env ruby
require 'yaml'
def yaml_to_scalar(node, anchors={})
case node
when Psych::Nodes::Scalar
node.value
when Psych::Nodes::Document
node.children.map do |child|
yaml_to_scalar(child, anchors)
View csv2md_table.rb
#!/usr/bin/env ruby
require 'csv'
body = if ARGV.length > 0
ARGF.read
else
STDIN.read
end
csv = CSV.new(body)
View Dockerfile
FROM ruby:2.6-alpine
ENV LANG=C.UTF-8 \
TZ=Asia/Tokyo \
ROOT_PATH=/app \
BUNDLE_JOBS=4 \
BUNDLE_PATH=/gems
VOLUME /gems
View scraping_valunerability.rb
require 'open-uri'
require 'nokogiri'
ROOT_URI = 'https://www.google.com/search?source=hp&ei=K5YWXf3qBozK8wXsgqOYDQ&q=%E8%84%86%E5%BC%B1%E6%80%A7&oq=%E8%84%86%E5%BC%B1%E6%80%A7&gs_l=psy-ab.3..0j0i131j0l6.4101.7361..7805...2.0..0.74.1039.17......0....1..gws-wiz.....0..0i4j0i131i4j0i4i70i257.JdDB9CrU7j0'
google_html = nil
open(ROOT_URI) do |f|
google_html = f.read
end
google = Nokogiri::HTML(google_html)
REG_DOUBLE_SLASH = %r(\A//)
@yalab
yalab / find_copy_and_paste_method.rb
Created Mar 13, 2019
find method that write by copy and paste.
View find_copy_and_paste_method.rb
# USAGE find_copy_and_paste_method.rb MOD_NAME
Rails.application.eager_load!
base_class = ARGV[0].constantize
def all_subclasses(klasses)
if klasses == []
klasses
else
klasses.map{|k| all_subclasses(k.subclasses) << klasses }.flatten
end
end
View process-attach.md

別ウインドウの pts を調べる

vagrant@ubuntu-xenial:~$ w
 07:50:17 up 27 min,  3 users,  load average: 1.17, 1.12, 0.95
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
vagrant  pts/0    10.0.2.2         07:23   26:25   0.30s  0.00s /bin/sh -c set 
vagrant  pts/1    10.0.2.2         07:24    1.00s  0.06s  0.00s w
vagrant  pts/2    10.0.2.2         07:25   57.00s  0.04s  0.04s -bash
@yalab
yalab / sprockets-extend.rb
Created Apr 7, 2018
User definition sprockets function
View sprockets-extend.rb
module Sprockets::SassProcessor::Functions
def cdn_path(path, options={})
prefix = if (asset_host = Rails.application.config.action_controller.asset_host)
asset_host.scan(%r(/[^/]+\Z)).first
else
""
end
prefixed = prefix + asset_path(path, options).to_s
Sass::Script::String.new(prefixed)
end
View cli-wifi-connect.sh
wpa_passphrase SSID
# => write your WIFI PASSWORD then show encoded password
iwconfig wlan0 essid SSID enc s:ENCODED_PASSWORD
You can’t perform that action at this time.