Skip to content

Instantly share code, notes, and snippets.

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);
var _ = {
map: function(arr, fn) {
var r = [];
for (var i = 0, len = arr.length; i < len; i++) {
r.push(fn(arr[i]));
}
return r;
},
filter: function(arr, fn) {
@s-shin
s-shin / scrollfix-at-bottom.js
Last active March 23, 2016 05:58
not sufficiently tested
import _ from "underscore";
export default function scrollfixAtBottom(opts) {
opts = _.assign({
elFixed: document.querySelector(".js-scrollfix-bottom"),
elRelative: document.querySelector(".js-scrollfix-bottom-rel"),
bottom: 10,
throttle: 50,
debug: false
}, opts);
@s-shin
s-shin / child.php
Created February 29, 2016 05:57
IPC example by popen in ruby with timeout.
<?php
$num_iterates = $argv[1];
echo "iterates: $num_iterates\n";
foreach (range(1, $num_iterates) as $i) {
sleep($i);
echo "$i\n";
echo "ping\n";
@s-shin
s-shin / icomoon-selection-json-to-android-string-xml.sh
Last active February 24, 2016 14:13
One-liner to convert icomoon's selection.json to android's string xml.
ruby -rjson -e 'puts "<resources>"; JSON.parse(File.read(ARGV[0]))["icons"].each {|icon| puts " <string name=\"#{ARGV[1]}_#{icon["properties"]["name"]}\">&#x#{icon["properties"]["code"].to_s(16)};</string>"}; puts "</resources>"' path/to/icomoon/selection.json prefix > path/to/values/fonts.xml
_ = require "lodash"
class BrainWrapper
constructor: (@brain, @key, @initialData, @migrator = _.identity) ->
get: (path = null, defaultValue = null) ->
data = @_get()
if path then _.get(data, path, defaultValue) else data
set: (path, value) ->
@s-shin
s-shin / stacked-graph-transformer.rb
Created February 17, 2016 04:58
car data.tsv | ruby stacked-graph-transformer.rb
class StackedGraphTransformer
# @param [IO] io
def initialize(io)
@io = io
end
def gets_tsv
(line = @io.gets) ? line.chomp.split("\t") : nil
end