Skip to content

Instantly share code, notes, and snippets.

package main
import (
"compress/gzip"
"io"
"log"
"net"
)
type hello struct {
@s-shin
s-shin / tcp-gzip.go
Created June 7, 2017 04:51
An example of tcp and gzip in golang.
package main
import (
"compress/gzip"
"io"
"log"
"net"
)
func main() {
@s-shin
s-shin / yml2sh
Created May 18, 2017 06:52
Example: `echo "$(eval "$(echo "{ foo: { bar: [fizz, buzz] } }" | yml2sh)"; echo "$(foo.bar)")"` => fizz\tbuzz
#!/usr/bin/env ruby
require 'yaml'
def puts_sh_kv(key, value)
escaped_value = value.gsub(/"/, '\\"')
puts %(function #{key}() { echo "#{escaped_value}"; })
end
def print_sh(data, key_prefix: '')
data.each do |key, value|
#!/usr/bin/env ruby
require 'optparse'
# @param bytes [String] Byte sequence as needle.
# @param io [IO] IO object as haystack.
# @param max [Integer, nil] Stop search when `max` number of `bytes` are found.
# @return [Array<Integer>]
def search(bytes, io, max = nil)
buf_size = bytes.size * 10
buf = ''
@s-shin
s-shin / a.cpp
Last active April 24, 2017 04:09
#include "foo.h"
int get_foo_a() { return foo; }
package main
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
package main
import (
"fmt"
)
func その名は(名探偵, コナン string) {
fmt.Println(名探偵 + "=" + コナン)
}
@s-shin
s-shin / semver.rb
Created February 24, 2017 10:55
Simple class to handle SemVer (http://semver.org/).
class SemVer
include Comparable
attr_accessor :major, :minor, :patch, :prerelease, :build_metadata
@@re = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?(?:\+((?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?$/
def initialize(major, minor, patch, prerelease = "", build_metadata = "")
@major = major.to_i
@minor = minor.to_i
@s-shin
s-shin / y2j
Created February 3, 2017 09:23
command converting yaml to json
#!/bin/bash
set -eu
ruby -ryaml -rjson -e "puts JSON.dump(YAML.load(STDIN))"
#include <iostream>
#include <memory>
std::shared_ptr<int*> CreatePointerNG(int v) {
auto foo = std::make_shared<int>(v);
return std::make_shared<int*>(foo.get());
}
std::shared_ptr<int*> CreatePointerOK(int v) {
auto foo = std::make_shared<int>(v);