This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <memory> | |
#include <cstdlib> | |
#include <iostream> | |
template<class T> | |
class MyAllocator : public std::allocator<T> { | |
public: | |
MyAllocator() {} | |
MyAllocator(const MyAllocator& x) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
datetime.datetime.now().strftime("%Y%m%d_%H%M") | |
# 2015/1/1 23:45 20150101_2345 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. 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 . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @NounExtractor | |
constructor: () -> | |
@segmenter = new TinySegmenter() | |
extractNouns: (text) -> | |
words = @segmenter.segment(text) | |
nouns = [] | |
for word in words | |
if @isNoun(word) | |
nouns.push(word) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: | |
# |