Skip to content

Instantly share code, notes, and snippets.

awk random extract line

$ awk '{ srand(); if(NR == (n = int(rand() * 124478))){print n, $0}}' FILEPATH
@yalab
yalab / run-pod.sh
Last active September 6, 2021 00:03
#!/usr/bin/env bash
while getopts i:n: OPT
do
case "$OPT" in
"n") NAMESPACE="$OPTARG";
;;
"i") IMAGE="$OPTARG";
;;
esac
inquiries:
mail_address: Faker::Internet.email
nickname: Faker::Games::Pokemon.name
message_body: Faker::Lorem.paragraph
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
#!/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)
#!/usr/bin/env ruby
require 'csv'
body = if ARGV.length > 0
ARGF.read
else
STDIN.read
end
csv = CSV.new(body)
FROM ruby:2.6-alpine
ENV LANG=C.UTF-8 \
TZ=Asia/Tokyo \
ROOT_PATH=/app \
BUNDLE_JOBS=4 \
BUNDLE_PATH=/gems
VOLUME /gems
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 March 13, 2019 06:59
find method that write by copy and paste.
# 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

別ウインドウの 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