Skip to content

Instantly share code, notes, and snippets.

Avatar

Taka necojackarc

View GitHub Profile
@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 / 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": [
@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 / 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 / _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 / 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

View Simulate document click events on iOS.js
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 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)
View Run test scripts for all packages under a Yarn workspace with jq.md
$ yarn workspaces info --json | jq -rc '.data | fromjson | keys | .[]' | sed 's/^/yarn workspace /g' | sed 's/$/ test/g' | sh
View .rubocop.yml
AllCops:
TargetRubyVersion: ~
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'vendor/**/*'
- 'bin/*'
- 'config/**/*'
- 'db/**/*'