Skip to content

Instantly share code, notes, and snippets.

@satooshi
satooshi / QueueRunner.rb
Created August 12, 2019 12:29
Run rspec in parallel
#!/usr/bin/env ruby
require 'concurrent'
require 'coverage'
require 'parallel'
require 'rspec/core'
# serializable notifications inter processes
class FailedExampleNotification
require "pg"
DB.open "postgres://postgres:postgres@localhost:5432/blog_development" do |db|
db.transaction do |tx|
conn = tx.connection
pp conn.scalar "select count(*) from articles" # => 5
pp conn.exec "insert into articles (title, url, markdown, created_at, updated_at) values ('title', 'url', 'markdown', now(), now())"
pp db.scalar "select count(*) from articles" # => 5 (because this established another connection)
pp conn.scalar "select count(*) from articles" # => 6
Unhandled exception: (Time::Location::InvalidTZDataError)
from /usr/local/Cellar/crystal/0.27.0/src/time/location/loader.cr:86:5 in 'read_zoneinfo'
from /usr/local/Cellar/crystal/0.27.0/src/crystal/system/unix/time.cr:59:9 in 'load_localtime'
from /usr/local/Cellar/crystal/0.27.0/src/time/location.cr:339:10 in 'load_local'
from /usr/local/Cellar/crystal/0.27.0/src/time/location.cr:320:38 in 'local'
from /usr/local/Cellar/crystal/0.27.0/src/time.cr:367:16 in 'now'
from lib/amber/src/amber/server/server.cr:55:14 in 'start'
from lib/amber/src/amber/server/server.cr:50:9 in 'run'
from lib/amber/src/amber/server/server.cr:17:7 in 'start'
from src/blogway.cr:3:1 in '__crystal_main'
# spec/models/cat_spec.rb
require 'rails_helper.rb'
RSpec.describe Cat, type: :model do
# this is a test target model
let(:cat) { Cat.new(status: status) }
# this block describes Cat#nyan instance method
# when you reference an instance method, write `Class#method`
# and for a class method, write 'Class.method'
@satooshi
satooshi / node installation on docker
Last active December 24, 2016 09:36
node installation on docker
# Dockerfile
------------------
FROM library/ubuntu:16.04
RUN apt-get -y update && apt-get install -y build-essential git python libssl-dev curl
# install nodebrew, node
ENV NODEBREW_ROOT=/usr/local/nodebrew
ENV PATH=/usr/local/nodebrew/current/bin:$PATH
RUN export NODE_VERSION=v4.3.2 && curl -L git.io/nodebrew | perl - setup \
&& nodebrew install-binary $NODE_VERSION \
@satooshi
satooshi / docker introduction
Last active December 24, 2016 05:40
docker introduction
mkdir mydockerbuild
cd mydockerbuild
vi Dockerfile
FROM library/ubuntu:16.04
RUN apt-get -y update && apt-get install -y build-essential git silversearcher-ag python libssl-dev
CMD date
docker build -t echo-date .
docker images
@satooshi
satooshi / VietnameseUnicodeNormalizationFormCAndD.php
Last active January 18, 2016 09:52
Get NFC and NFD string of Vietnamese characters.
<?php
# http://www.unicode.org/charts/PDF/U1E00.pdf
$targets = [
'aắằặấầẩậẳẵạàáâãảăẫ',
'eẽẹếềểễệèéêẻ',
'oốồổỗộờởơớỡòóôõỏọợ',
'iịìíĩỉ',
'uứừửưữựụùúũủ',
'yỳỷỹỵý'
@satooshi
satooshi / gist:608fd70c19cff35f4981
Last active October 30, 2015 15:28
unix socketを使う場合のnginxの設定
upstream backend {
server unix:/home/vagrant/prj/blog/tmp/sockets/puma.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/vagrant/prj/blog/public;
index index.html;
@satooshi
satooshi / gist:b310ca78f1f26d24cae1
Last active October 30, 2015 15:27
tcp通信する場合のnginxの設定
upstream backend {
server 127.0.0.1:3001;
}
# http://henteco-labs.com/labs/2014/04/14/rails-nginx/
server {
location / {
try_files $uri @proxy;
}
@satooshi
satooshi / notify.rb
Created October 27, 2014 09:02
Send a message to Mac OSX notification center.
def changed(file_path)
notify File.open(file_path, "rb").read
end
def notify(result)
messages = result.split("\n")
title = messages.shift
group = messages.shift
info = messages.join("\n")