Skip to content

Instantly share code, notes, and snippets.

View ichiban's full-sized avatar

Yutaka Ichibangase ichiban

View GitHub Profile
@ichiban
ichiban / crontab
Last active December 18, 2015 22:58
# envがあると動いた
# Begin Whenever generated tasks for: app
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
0,30 * * * * /bin/bash -l -c 'cd /var/www/app/current && env bundle exec script/rails runner -e staging '\''PostScheduled.post(-15.minutes.from_now..15.minutes.from_now)'\'' >> log/cron.log 2>&1'
# End Whenever generated tasks for: app
@ichiban
ichiban / gist:5926568
Last active December 19, 2015 08:38
How to upload a large SQLite3 table into Google Docs.
.mode tabs posts
.output /tmp/posts.tsv
select * from posts;
@ichiban
ichiban / application_controller.rb
Last active December 21, 2015 06:18
Set I18N locale based on HTTP_ACCEPT_LANGUAGE header.
class ApplicationController < ActionController::Base
# ...
before_filter :set_locale
# ...
def set_locale
logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
I18n.locale = locale_string(locale) if locale
@ichiban
ichiban / rails_admin.rb
Created October 23, 2013 01:38
Rails AdminとDoorkeeperを一緒に使うときは、この設定で幸せになれる気がする
# ...
# Include specific models (exclude the others):
config.included_models = Dir.new(Rails.root.join('app', 'models')).entries.map{|entry| $1.camelize if entry =~ /^(\w+)\.rb$/ }.compact! + ['Doorkeeper::Application', 'Doorkeeper::AccessGrant', 'Doorkeeper::AccessToken']
# ...
@ichiban
ichiban / datetime-picker-in-use.html
Created November 20, 2013 13:03
2-way bindings were broken with iOS Safari x input[type=datetime-local] x Angular.js. This directive fixed the problem for me.
<input type="datetime-local" datetime-picker ng-model="datetime" />
@ichiban
ichiban / csrf.js
Last active January 4, 2016 07:58
how to treat csrf-token in angular.js / rails
angular.module('app', [])
.config(['$httpProvider', function($httpProvider) {
var csrfToken = $('meta[name="csrf-token"]').attr('content');
$httpProvider.defaults.headers.common['X-CSRF-Token'] = csrfToken;
}]);
angular.module('app').controller('MainController', ['$scope', 'userResource', function($scope, userResource) {
$scope.current = {};
$scope.$watch('current.user', function(user) {
if (user) { return; }
var user = userResource();
user.then(function(user) {
$scope.current.user = user;
});
});
}]);
(function() {
'use strict';
var overlayVisible = 'overlay--visible';
var $document = $(document);
$document.on('overlay:open', function() {
var $body = $('body');
var $overlay = $('.overlay');
@ichiban
ichiban / grammar.ml
Created January 16, 2016 09:19
Earley Recognizer
open Batteries
(**** symbols ****)
type symbol =
| Terminal of UChar.t
| Nonterminal of Text.t
let symbol_to_text = function
| Terminal char -> Text.of_uchar char
@ichiban
ichiban / gist:c3a4b13e40ed36d5d291
Created February 14, 2016 07:16
HTTPパーサの進捗
$ cat post.txt | ./1l
Input:
POST /cgi-bin/process.cgi HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
Accept-Language: en-us
Accept-Encoding: gzip, deflate