Skip to content

Instantly share code, notes, and snippets.

@tk3
tk3 / basic_auth.rb
Last active December 10, 2015 07:30
ngx_mruby: basic authentication
def basic_auth
r = Nginx::Request.new
realm_name = r.var.realm_name
if r.headers_in["Authorization"].nil?
r.headers_out["WWW-Authenticate"] = %Q(Basic realm="#{realm_name}")
return Nginx::HTTP_UNAUTHORIZED
end
auth = r.headers_in["Authorization"]
@tk3
tk3 / trusterd.conf.rb
Last active August 29, 2015 14:16
Trusterd で Basic 認証 (骨組み)
SERVER_NAME = "Trusterd"
SERVER_VERSION = "0.0.1"
SERVER_DESCRIPTION = "#{SERVER_NAME}/#{SERVER_VERSION}"
root_dir = "/home/vagrant/trusterd"
s = HTTP2::Server.new({
:port => 8080,
:document_root => "#{root_dir}/htdocs",
:server_name => SERVER_DESCRIPTION,
@tk3
tk3 / sample.rb
Created March 12, 2015 17:38
md5 hash
#require "digest"
password = 'user02'
key = '$apr1$'
salt = 'PD3O5t9N'
h1 = Digest::MD5.new
h1.update(password)
h1.update(key)
h1.update(salt)
@tk3
tk3 / build_config.rb
Created May 5, 2015 16:44
RFC 6238 sample code; Java to mruby
MRuby::Build.new do |conf|
toolchain :gcc
conf.gem :github => 'iij/mruby-digest'
conf.gem :github => 'iij/mruby-pack'
conf.gembox 'full-core'
end
@tk3
tk3 / build_config.yml
Created August 3, 2015 15:17
build_config.rb to YAML
build:
host:
toolchain: gcc
debug: enable
gembox: default
gem:
- 'examples/mrbgems/c_and_ruby_extension_example'
-
'examples/mrbgems/c_extension_example':
cc:
@tk3
tk3 / sample.rb
Created October 31, 2015 03:12
mrbgem.rake のパラメーターを parse する
#!/usr/bin/env ruby
class Foo
def self.parse(src)
instance_eval(src)
end
class MRuby
class Gem
class Specification
@tk3
tk3 / sample_curl.c
Last active October 13, 2022 18:11
curl を使って HTTP Get
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "curl/curl.h"
typedef struct {
char *m;
size_t size;
} Memory;
@tk3
tk3 / sample.rs
Created November 25, 2017 11:27
str sample - rust
// str - Rust https://doc.rust-lang.org/std/primitive.str.html
fn main() {
test_str();
test_str_contains();
test_str_find();
test_str_splitn();
}
fn test_str() {
assert_eq!("abc".len(), 3);
@tk3
tk3 / basic-theme.yml
Created January 6, 2018 07:18
sample theme
# ref. https://github.com/asciidoctor/asciidoctor-pdf/blob/master/docs/theming-guide.adoc#language-overview
page:
layout: portrait
margin: [0.75in, 1in, 0.75in, 1in]
size: Letter
base:
font_color: #333333
font_family: Times-Roman
font_size: 12
line_height_length: 17
@tk3
tk3 / Gemfile
Last active January 10, 2018 06:52
Backlog Contribution graph
source 'https://rubygems.org'
gem "faraday"
gem "faraday_middleware"
gem "thor"