Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <vector>
#include <random>
#include <chrono>
#include <thread>
#include <unordered_map>
#include <cmath>
#include <algorithm>
struct Plus
@sawamur
sawamur / gist:8841642
Last active August 29, 2015 13:56
猫十則

猫十則

電通鬼十則をブラック要素を薄めるために猫っぽくしてみました。ゆとりな人でも納得できる行動指針になりました:paw_prints:

  1. 仕事は自ら創るべきで、与えられるものではないニャン
  2. 仕事とは、先手先手と働き掛けて行くことで、受け身でやるべきものではないニャン
  3. 大きな仕事と取り組め、小さな仕事はおのれを小さくするニャン
  4. 難しい仕事を狙え、そしてこれを成し遂げるところに進歩があるニャン
  5. 取り組んだら放すニャ、○されても放すニャ、目的完遂までは…。
  6. 周囲を引きずり回せ、引きずるのと引きずられるのとでは、永い間に天地のひらきができるニャン
@sawamur
sawamur / rule_of_baseball.rb
Last active December 16, 2015 21:49
Rule of baseball in ruby - Last weekend, I went to see baseball game with my six years old kid. I found that the rule of baseball is quite difficult. For example, treating foul ball as strike if the count of strike is under two. There are lots of conditional procedures. So, I write the rule in ruby. Looks nice,isn't it?
tesms = [ Team.new("baystars"), Team.new("swallows") ]
9.times do |inning|
2.times do |half|
if inning == 8 and half == 1 and teams[0].score > teams[1].score
break
end
pitcher = teams.first.pitcher
out = 0
runners = []
@sawamur
sawamur / gist:5212601
Created March 21, 2013 12:13
10年以上まえに書いたperlのコードをひろったので
package Perltag;
#####################################################################
#use strict 'subs';
use vars qw($tmpl $Perltagscript $Script $Package $error
$default_kcode $default_TraceVars $ENCODING $MIMETYPE
$glob @glob %glob $n $VERSION $seed $LANG $CONTENT_LENGTH);
$MIMETYPE = 'text/html';
$ENCODING = 'Shift_JIS'; # or euc-jp/iso-2022-jp/iso-8859-1 etc..
#$LANG = 'ja'; # 'ja' activates japanese mode
@sawamur
sawamur / gist:4256670
Created December 11, 2012 07:57
sequence diagram markup language / Draft
user#foo -> server#web1 -sql-> db
true: ->
#web1 -mail-> user#foo
user -> server#web1 -> api#twitter
true: ->
server#web1 -> api#facebook
true: ->
db -> server#web1
false: ->
@sawamur
sawamur / gist:4066212
Created November 13, 2012 15:08
casper2
casper.start "http://twitter.com",->
@fill "form[action='https://twitter.com/sessions']"
,{"session[username_or_email]": "foobar","session[password]": "xxxxx"}
,true
casper.then ->
console.log @getCurrentUrl()
@click "#tweet-box-mini-home-profile"
casper.then ->
@sawamur
sawamur / gist:4066035
Created November 13, 2012 14:32
Casper Sample
casper = require('casper').create()
casper.start "http://twitter.com/sawamur"
casper.then ->
@test.assertNotVisible(".signup-only")
@click ".js-follow-btn:nth-of-type(1)"
casper.then ->
@test.assertVisible(".signup-only")
# from string
addrs = Doko.parse("..\n住所\n 東京都港区芝浦3-41 \n..\n...")
p addrs #=> ["東京都港区芝浦3-41"]
# from url
addrs = Doko.parse("http://r.tabelog.com/tokyo/A....")
p addrs #=> ["神奈川県横浜市中区.."]
@sawamur
sawamur / gist:1508380
Created December 22, 2011 00:38
JS中級コース向 サンプルコード
// 実装 : 一箇所バグあり
Date.prototype.strftime = (function () {
function strftime(format) {
var date = this;
return (format + "").replace(/%([a-zA-Z])/g,
function (m, f) {
var formatter = Date.formats && Date.formats[f];
@sawamur
sawamur / gist:1363165
Created November 14, 2011 03:26
ある緯度経度範囲内にある駅データをdbpediaから取得するSPARQLクエリ
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbpedia_ont: <http://dbpedia.org/ontology/>
SELECT * WHERE {
?link rdfs:label ?title;
rdfs:comment ?comment;
geo:lat ?lat;
geo:long ?long.
?link rdf:type dbpedia_ont:Station.