Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
😃

petitviolet petitviolet

🕶️
😃
View GitHub Profile
@petitviolet
petitviolet / rspec_any_instance_count.rb
Created Aug 16, 2021
allow_any_instance_of to count up the number of method calls across different instances
View rspec_any_instance_count.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'rspec', '~> 3.0'
end
@petitviolet
petitviolet / main.js
Created May 26, 2021
Subscribe a web page by GoogleAppScript
View main.js
const URL = 'https://example.com';
const CELL = 'A1'
const MAIL_TO = 'mail@example.com';
// Create a trigger to run `main` periodically
function main() {
const sheet = SpreadsheetApp.getActiveSheet();
const lastDate = readLastDate(sheet);
const today = Utilities.formatDate(new Date(), 'UTC', 'yyyy-MM-dd');
if (lastDate === null || lastDate == today) {
View rails_call_another_controller_action.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "6.0.0"
@petitviolet
petitviolet / Cargo.toml
Last active Sep 6, 2020
Simple logger implementation in Rust
View Cargo.toml
[dependencies]
log = { version = "0.4", features = [ "std" ] }
@petitviolet
petitviolet / main.dig
Created Apr 30, 2020
digdag's `http_call>` operator sample
View main.dig
+run_workflow:
http_call>: http://$(ip):8000/http_call_dig
retry: false
_retry: 2
@petitviolet
petitviolet / route.go
Created Apr 29, 2020
oEmbed API for blog.petitviolet.net
View route.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
@petitviolet
petitviolet / rstruct.rb
Last active Jan 12, 2020
Struct implemented with Ruby
View rstruct.rb
module Rstruct
def self.new(*attributes)
names = caller.map do |stack|
# ".../hoge.rb:7:in `<module:Hoge>'"
if (m = stack.match(/\A.+in `<(module|class):(.+)>.+/))
m[2]
end
end.reject(&:nil?)
file_name, line_num = caller[0].split(':')
line_executed = File.readlines(file_name)[line_num.to_i - 1]
@petitviolet
petitviolet / graphiql.html
Created Dec 21, 2019
GraphQL Web UI with text box to edit AccessToken
View graphiql.html
<!-- https://github.com/howtographql/sangria/blob/master/src/main/resources/graphiql.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex" />
<meta name="referrer" content="origin" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>GraphiQL</title>
<style>
@petitviolet
petitviolet / tracer.rb
Created Dec 17, 2019
Tracing method calls using TracePoint
View tracer.rb
class Debugger
def initialize(events)
@tp = TracePoint.new(*(events || %i[call b_call raise])) do |tp|
tp.binding.irb
end
@tp.disable
end
def trace(&block)
@tp.enable
View cvimrc.vim
" general
set autoupdategist " gistの設定を自動反映
let scrollstep = 150
let fullpagescrollpercent = 100
set smoothscroll
set noautofocus " サイトを開いた時に入力欄にフォーカスが奪われるのを抑止
let searchlimit = 20
let barposition = "bottom"