Skip to content

Instantly share code, notes, and snippets.

View labocho's full-sized avatar

labocho

View GitHub Profile
@labocho
labocho / webpack.config.js
Last active September 1, 2021 06:03
webpack etc. configuration for Rails application
// webpack.config.js for Rails application
// Other configurations:
// tsconfig.json: https://gist.github.com/labocho/0afa689d18dc5b2d434ec0ff9a6673bb
// .eslintrc.yml: https://gist.github.com/labocho/b3665e878db2b30b79abe43d5f1e3a25
// Useful scripts:
// "dev": "rm -rf public/packs && webpack --progress",
// "build": "rm -rf public/packs && webpack --mode=production",
// "lint": "eslint app/javascript",
// "lint-fix": "eslint app/javascript --fix",
// "watch": "webpack --progress --watch"
import type {VNode, VueConstructor} from "vue";
import Vue from "vue";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function mountView(el: Element, component: VueConstructor, properties: any, components: any): void {
// eslint-disable-next-line no-new
new Vue({
components,
el,
render: (createElement): VNode => {
@labocho
labocho / strict_accessor.rb
Last active August 17, 2021 06:11
Change Hash or Array's `[]` to `fetch` recursively
# Usage:
# h = StrictAccessor.strictify({a: 1, b: [{c: 3}]})
# h[:c] # KeyError
# h[:b][1] # IndexError
module StrictAccessor
def self.strictify(object)
case object
when Array
object.map {|e| strictify(e) }.extend(self)
when Hash
@labocho
labocho / view_renderer.rb
Created April 20, 2021 06:32
Rails view renderer
class ViewRenderer
class ViewRenderingController < ActionController::Base
include Rails.application.routes.url_helpers
include ApplicationHelper
def protect_against_forgery?
false
end
end
@labocho
labocho / numbers2csv
Last active March 23, 2021 06:42
numbers2csv: Command to convert Numbers file to CSV
#!/usr/bin/env ruby
# Usage: numbers2csv foo.numbers > foo.csv
require "open3"
require "tempfile"
def osascript(script, *args)
out, err, status = Open3.capture3("osascript", "-l", "JavaScript", "-e", script, *args)
unless status.success?
raise ScriptError, err
require "logger"
$stdout.sync = true
logger = Logger.new($stdout)
logger.formatter = -> (severity, datetime, _progname, message) {
{
severity: severity,
time: datetime.to_i,
}.merge(message).to_json + "\n"
}
@labocho
labocho / README.md
Last active April 10, 2020 07:40
Homebrew formula for mysql 5.7.22
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
curl https://gist.githubusercontent.com/labocho/f7da1dd8964d5ac50e5f399ef72973ab/raw/8e0572e6eef18536fdb129eb73de73a60685c449/mysql@5.7.rb > Formula/mysql@5.7.rb
brew install mysql@5.7
# to revert
git checkout Formula/mysql@5.7.rb
@labocho
labocho / benchmark_itamae_file_optimization.rb
Last active March 26, 2020 08:55
Benchmark of itamae file resource optimization
require "benchmark"
Benchmark.bm do |x|
x.report {
5.times do |i|
system("bundle exec itamae ssh --host=192.168.33.10 --user=itamae file_creation.rb", out: "/dev/null", err: "/dev/null") || raise
end
}
end
@labocho
labocho / sns_to_slack.py
Created January 24, 2020 09:50
Lambda function (python3.7) to send SNS message to Slack
import urllib.request
import json
import os
# https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/with-sns.html
def lambda_handler(event, context):
req = urllib.request.Request(
os.environ["SLACK_WEBHOOK_URL"],
json.dumps({
"text": event["Records"][0]["Sns"]["Subject"],
@labocho
labocho / a.yml
Created January 8, 2020 02:27
Example for add !inherit YAML tag to load another yaml file and override values
foo: !inherit
from: b.yml
override:
a:
b: !replace
d: 12345