Skip to content

Instantly share code, notes, and snippets.

@necojackarc
necojackarc / search_commit_msg
Created November 6, 2015 10:32
Getting commit massage samples script powered by http://commit-m.minamijoyo.com/
#!/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 / Use ActiveModelSerializers inside Jbuilder.md
Last active March 28, 2017 09:34
How to Use ActiveModelSerializers inside Jbuilder

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": [
@necojackarc
necojackarc / Install Matplotlib with Tk on openSUSE.md
Last active April 13, 2017 09:49
How to Install Matplotlib with Tk Backend on openSUSE

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 / Deploy Hubot with OpsWorks.md
Last active April 24, 2017 08:25
How to Deploy Hubot with OpsWorks

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 / _json_ld_breadcrumbs.html.erb
Last active November 6, 2017 01:58
Render breadcrumbs in JSON-LD with Breadcrumbs On Rails
<!-- app/views/layouts/_json_ld_breadcrumbs.html.erb -->
<script type="application/ld+json">
<%= render_breadcrumbs builder: Breadcrumbs::JsonLdBuilder %>
</script>
@necojackarc
necojackarc / Control Maintenance Mode (Render 503) by Env Vars with Rails.md
Last active February 10, 2018 19:52
How to Control Maintenance Mode (Render 503) by Env Vars with Rails

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

function initialize() {
if (!is_ios()) return;
let document_click_on_ios;
document.addEventListener('touchstart', () => {
document_click_on_ios = true;
});
document.addEventListener('touchmove', () => {
@necojackarc
necojackarc / text_file_pager.rb
Created November 1, 2015 14:04
You can get batches of lines from text files.
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)
$ yarn workspaces info --json | jq -rc '.data | fromjson | keys | .[]' | sed 's/^/yarn workspace /g' | sed 's/$/ test/g' | sh
AllCops:
TargetRubyVersion: ~
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'vendor/**/*'
- 'bin/*'
- 'config/**/*'
- 'db/**/*'