Skip to content

Instantly share code, notes, and snippets.

View ichiban's full-sized avatar

Yutaka Ichibangase ichiban

View GitHub Profile
@ichiban
ichiban / gist:06482c00de897009896d
Created March 2, 2016 04:50
HTTPサーバの進捗です。LWT難しい。
$ curl http://localhost:9000/
OK 200HTTP/1.1 Hello, World!
text/plain: Content-Type
@ichiban
ichiban / gist:887fb4894532c0a44b18
Created February 21, 2016 08:57
HTTPサーバの進捗(Content-Lengthが与えられてないときは0とみなすべき?)
$ ./1w
**** message begin ****
method: "GET"
uri: "/"
major: "1"
minor: "1"
field: "Host"
value: "localhost:9000"
field: "Connection"
value: "keep-alive"
@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
@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
(function() {
'use strict';
var overlayVisible = 'overlay--visible';
var $document = $(document);
$document.on('overlay:open', function() {
var $body = $('body');
var $overlay = $('.overlay');
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;
});
});
}]);
@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;
}]);
@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 / 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 / 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