Skip to content

Instantly share code, notes, and snippets.

@cocodrips
cocodrips / date.js
Created July 24, 2015 03:03
jsで日付好きな文字でjoinするのが見つからなかった
var date_string = function(d, join) {
//Date -> 20150101
var year = (d.getYear() + 1900).toString();
var month = ('0' + (d.getMonth() + 1).toString()).slice(-2);
var day = ('0' + d.getDate().toString()).slice(-2);
return year + join + month + join + day;
}
@cocodrips
cocodrips / kruskal.py
Created July 18, 2015 14:56
Kruskal法(最小全域木〜〜)
class UnionFind:
def __init__(self, n):
self.par = range(n)
self.rank = [0 for i in xrange(n)]
def find(self, x):
if self.par[x] == x:
return x
self.par[x] = self.find(self.par[x])
return self.par[x]
@cocodrips
cocodrips / easy.py
Last active August 29, 2015 14:25
TCO2015 2C easy
class YetAnotherCardGame:
def maxCards(self, petr, snuke):
petr = list(petr)
snuke = list(snuke)
petr.sort()
snuke.sort()
turn = min(len(petr) * 2, len(snuke) * 2)
#dp[turn][max] = length
#include <vector>
#include <memory>
#include <cstdlib>
#include <iostream>
template<class T>
class MyAllocator : public std::allocator<T> {
public:
MyAllocator() {}
MyAllocator(const MyAllocator& x) {}
@cocodrips
cocodrips / time.py
Created June 18, 2015 03:20
現在の時間を文字列で
import datetime
datetime.datetime.now().strftime("%Y%m%d_%H%M")
# 2015/1/1 23:45 20150101_2345
@cocodrips
cocodrips / avg.result
Last active August 29, 2015 14:18
Kaggleの数字判別-とりあえず平均値をとってみる
. o o .
. . o o o o o o .
. . o o o o o @ @ @ o . .
. . . o o @ @ @ @ @ @ @ o o .
. . o o @ @ @ @ @ @ @ @ @ o . .
. . o o o o o o o . o o o o o o .
@cocodrips
cocodrips / sqrt.py
Created March 30, 2015 17:50
簡易版 平方根の小数点以下を求める
def sqrt(n, m):
a, b = 5 * n, 5
for i in xrange(m):
if a >= b:
a -= b
b += 10
else:
a *= 100
b = b * 10 - (b % 10 * 10) + (b % 10)
return b
# Shell Question 1. ファイルが与えられます。ファイル中のすべての"."を"。"に置き換えるシェルスクリプトを書いてください。
# hoge.txt: hello, world!...,,,...,.;
sed -i "" "s/\./。/g;" test.txt
# Shell Question 2. /etc/以下のすべての .conf ファイルを列挙してください。
ls -R /etc | grep .conf$
# Shell Question 3. ヘッダつきのCSVファイルが与えられます。ヘッダの行を取り除いたファイルを作ってください。
tail -n +2 hoge.csv > hoge2.csv
@cocodrips
cocodrips / NounExtractor.coffee
Created February 16, 2015 11:49
TinySegmenterで名詞を取り出す(精度△ 早さ◎)
class @NounExtractor
constructor: () ->
@segmenter = new TinySegmenter()
extractNouns: (text) ->
words = @segmenter.segment(text)
nouns = []
for word in words
if @isNoun(word)
nouns.push(word)
@cocodrips
cocodrips / cocodrips.zsh-theme
Created February 4, 2015 02:45
Original zsh theme. (+ wedisagree.zsh-theme)
# On a mac with snow leopard, for nicer terminal colours:
# - Install SIMBL: http://www.culater.net/software/SIMBL/SIMBL.php
# - Download'Terminal-Colours': http://bwaht.net/code/TerminalColours.bundle.zip
# - Place that bundle in ~/Library/Application\ Support/SIMBL/Plugins (create that folder if it doesn't exist)
# - Open Terminal preferences. Go to Settings -> Text -> More
# - Change default colours to your liking.
#
# Here are the colours from Textmate's Monokai theme:
#