Skip to content

Instantly share code, notes, and snippets.

View niaeashes's full-sized avatar

Nia niaeashes

  • Fukuoka
  • 08:18 (UTC +09:00)
View GitHub Profile
@niaeashes
niaeashes / mass_asignment_spec.rb
Created February 1, 2014 05:41
Testing presence validator watches relational record.
require 'spec_helper'
RSpec.configure { |c| c.filter_run_excluding mass_assignment: true }
module MassAssignment
class List < ActiveRecord::Base
self.table_name = :mass_assignment_lists
has_many :items, class_name: 'MassAssignment::Item'
end
class EmailValidator < ActiveModel::EachValidator
# Email address regex is copied from http://emailregex.com on "Ruby (simpler version)"
def validate_each(record, attr_name, value)
if ! ( value.blank? && options[:allow_blank] )
record.errors.add(attr_name, :invalid_email, options) unless value =~ /\A([\w+\-][\w+\-.]*[\w+\-]|[\w+\-.])@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
end
end
end
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'application'
set :repo_url, 'repository'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
## Install
### CentOS 7.x
#### Install basic packages
```
yum update -y
rpm -ivh http://packages.groonga.org/centos/groonga-release-1.1.0-1.noarch.rpm
yum install -y nginx openssl openssl-devel mariadb-server mariadb-devel groonga groonga-tokenizer-mecab nodejs npm mongodb mongodb-server
HEAD https://api.rubygems.org/api/v1/dependencies
200 OK
GET https://api.rubygems.org/api/v1/dependencies?gems=rroonga
200 OK
GET https://api.rubygems.org/api/v1/dependencies?gems=archive-zip,groonga-client,json,pkg-config
200 OK
GET https://api.rubygems.org/api/v1/dependencies?gems=gqtp,groonga-command,io-like
200 OK
Downloading gem io-like-0.3.0.gem
GET https://api.rubygems.org/gems/io-like-0.3.0.gem
'use strict'
import pluralize from 'pluralize'
import ApiRequest from 'lib/ApiRequest'
import { SubmissionError } from 'redux-form'
const ADD_API_RESOURCE = '@api/ADD_RESOURCE'
const REMOVE_API_RESOURCE = '@api/REMOVE_RESOURCE'
require 'active_support'
module A
extend ::ActiveSupport::Concern
class_methods do
def sample=value
@sample = value
end
@niaeashes
niaeashes / gist:3641e0ffe5527683c5e10820b2ca50d8
Created November 29, 2017 12:28
車輪の再製造・原稿
「車輪の再発明」という言葉があります。
これは「すでによく知られている物事の解決手段である車輪のことを知らないために、車輪を自らのエネルギーで再発明してしまう」ことの無駄を揶揄した言葉です。
ぼくたちは無知故に、すでに解決された問題に再挑戦することがあり、そしてそれは多くの場合、徒労に終わります。なぜなら、この世界にはすでに、車輪の設計図があるからです。
設計図のとおりに車輪を作れば、誰もが、重い荷物を運ぶ時の摩擦係数から解放されます。
車輪とは何でしょうか?
ぼくたちはパッケージされた無数のライブラリを、gemやyarnやpipやyumやcocoa-podsで管理し、ダウンロードし、インストールし、メモリ上にロードし、実行しています。
これらのライブラリたちは、ぼくたちを多くの苦難から救ってくれる便利な武器であると同時に、「なにかを実装しなくても良い」という甘い誘惑でもあります。
すでに実装を終えたライブラリは、ぼくたちがそれをインストールしさえすれば、何らかの手段でぼくたちの課題を解決してくれます。
@niaeashes
niaeashes / run.js
Created March 11, 2019 10:32
位置参照情報ダウンロードサービスからデータを落としてきて適当に整形して JSON にまとめる感じのやつ
// http://nlftp.mlit.go.jp/isj/agreement.html
const csv2json = require('csv2json');
const iconv = require("iconv-lite")
const fs = require('fs')
const path = require('path')
const items = fs.readdirSync(__dirname)
const promises = items.map(async (name) => {
const filepath = path.join(__dirname, name)
@niaeashes
niaeashes / HexCell.swift
Created December 29, 2019 01:46
ゲーム作る.Hex座標系.log
class HexCell {
let coordinate: HexCoordinate
private(set) var field: Field = .none
private var isFreezed: Bool = false
init(coordinate: HexCoordinate) {
self.coordinate = coordinate
}