Skip to content

Instantly share code, notes, and snippets.

Avatar

Taka necojackarc

View GitHub Profile
@necojackarc
necojackarc / .eslintrc.js
Last active Dec 23, 2020
My ESLint configuration
View .eslintrc.js
module.exports = {
parserOptions: {
ecmaVersion: 2020,
},
env: {
es6: true,
},
root: true,
extends: 'eslint:recommended',
rules: {
@necojackarc
necojackarc / _json_ld_breadcrumbs.html.erb
Last active Nov 6, 2017
Render breadcrumbs in JSON-LD with Breadcrumbs On Rails
View _json_ld_breadcrumbs.html.erb
<!-- app/views/layouts/_json_ld_breadcrumbs.html.erb -->
<script type="application/ld+json">
<%= render_breadcrumbs builder: Breadcrumbs::JsonLdBuilder %>
</script>
@necojackarc
necojackarc / Deploy Hubot with OpsWorks.md
Last active Apr 24, 2017
How to Deploy Hubot with OpsWorks
View Deploy Hubot with OpsWorks.md

Procedure

  1. Create a new custom cookbook for Hubot
  2. Create a Node.js stack and an app on OpsWorks
  3. Set the recipe in "Deploy" section

Custom Cookbook for Hubot

Put two files as below:

  • hubot/recipes/deploy.rb
  • hubot/templates/default/bin_hubot.erb
@necojackarc
necojackarc / Install Matplotlib with Tk on openSUSE.md
Last active Apr 13, 2017
How to Install Matplotlib with Tk Backend on openSUSE
View Install Matplotlib with Tk on openSUSE.md

Matplotlib's default background is agg, which doesn't have GUI. It means that show() doesn't show any plots on GUI.

That will never show any window, your matplotlib is configured to use agg, which is no gui version of output. Install a gui backend like python-matplotlib-qt4, python-matplotlib-tk and try again. https://forums.opensuse.org/showthread.php/494173-matplotlib-fails-to-show-plots-after-latest-update-from-the-Sciencerepolistory

So, let's configure Matplotlib to use TkAgg, which is really easy to set up:

@necojackarc
necojackarc / Control Maintenance Mode (Render 503) by Env Vars with Rails.md
Last active Feb 10, 2018
How to Control Maintenance Mode (Render 503) by Env Vars with Rails
View Control Maintenance Mode (Render 503) by Env Vars with Rails.md

Environment variables

Key VALUE
MAINTENANCE_MODE When "true", your Rails app runs as maintenance mode
ALLOWED_IPS Set IP addresses you allow to access your Rails app when maintenance mode

Example

@necojackarc
necojackarc / Use ActiveModelSerializers inside Jbuilder.md
Last active Mar 28, 2017
How to Use ActiveModelSerializers inside Jbuilder
View Use ActiveModelSerializers inside Jbuilder.md

Background

ActiveModelSerializers (AMS) is often said "an alternative to Jbuilder", but AMS is a kind of decorator which knows only how to serialize the target objects. On the other hand, Jbuilder is a library for the view of MVC.

So, it's a bit tough with only AMS to compose complex JSONs like this:

{
 "users": [
View Delete all merged branches except for ones you want to leave.md

Easy to check which branches will be deleted by removing at the bottom of | sh :)

git branch -r --merged master | sed -e 's#origin/#:#g' | egrep -v 'master|release|ADD BRANCH NAMES YOU WANT TO LEAVE' | sed 's/^/git push origin'/g | sh
@necojackarc
necojackarc / active_job_retry_controlable.rb
Last active Jun 30, 2021
To enable ActiveJob to control retry
View active_job_retry_controlable.rb
module ActiveJobRetryControlable
extend ActiveSupport::Concern
DEFAULT_RETRY_LIMIT = 5
attr_reader :attempt_number
module ClassMethods
def retry_limit(retry_limit)
@retry_limit = retry_limit
@necojackarc
necojackarc / search_commit_msg
Created Nov 6, 2015
Getting commit massage samples script powered by http://commit-m.minamijoyo.com/
View search_commit_msg
#!/usr/bin/env ruby
require "net/http"
require "uri"
require "nokogiri"
params = { keyword: ARGV.join("\s") }
uri = URI.parse("http://commit-m.minamijoyo.com/commits/search")
uri.query = URI.encode_www_form(params)
@necojackarc
necojackarc / text_file_pager.rb
Created Nov 1, 2015
You can get batches of lines from text files.
View text_file_pager.rb
class TextFilePager
DEFAULT_BATCH_SIZE = 1000
def initialize(file_path, skip_header: false, delete_line_break: false)
@file_path = file_path
@skip_header = skip_header
@delete_line_break = delete_line_break
end
def batch_line(batch_size: DEFAULT_BATCH_SIZE)