Skip to content

Instantly share code, notes, and snippets.

View nafu's full-sized avatar
🧗
Keep exploring

Fumiya Nakamura nafu

🧗
Keep exploring
View GitHub Profile
@nafu
nafu / wget_webserver.rb
Created October 13, 2014 16:01
WEBrick for Wget
require 'webrick'
class TestContentServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
res.body = get_body(req.path)
res.content_type = WEBrick::HTTPUtils.mime_type(
req.path_info, WEBrick::HTTPUtils::DefaultMimeTypes)
end
def get_body(path)
@nafu
nafu / circle.yml
Created November 15, 2014 16:07
circle.yml for rails
deployment:
production:
branch: master
commands:
- heroku maintenance:on --app production
- heroku scale worker=0 --app production
- git push -f git@heroku.com:production.git $CIRCLE_SHA1:refs/heads/master
- heroku run 'rake db:migrate; rake db:seed' --app production
- heroku maintenance:off --app production
staging:
@nafu
nafu / gist:8ded244dd4f670563d1c
Created November 29, 2014 17:09
Swift Sequence
// Swift Sequence
import UIKit
var str = "Hello, playground"
class Cart<T> {
var items: [T]
init(items: [T]) {
@nafu
nafu / gist:f65cddde027224317157
Last active August 29, 2015 14:10
Class to String in Swift
class Model {
class func classString() -> String {
return NSStringFromClass(self.classFromCoder)
}
}
@nafu
nafu / file0.txt
Created February 7, 2015 22:48
GitHubのCompare View URLsから比較対象のSHA1を抽出する ref: http://qiita.com/nafu/items/7177c8818f00bc0fcdbd
var="https://github.com/user/repo/compare/049508ce0e26...286b18317092"
echo ${var#*compare/}
# 049508ce0e26...286b18317092
@nafu
nafu / 0_reuse_code.js
Last active August 29, 2015 14:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nafu
nafu / newton_raphson_sample
Created February 13, 2013 11:33
Newton-Raphson ( for root finding)
epsilon = 0.01
y = 1234567.0
guess = y/2.0
while abs(guess*guess - y) >= epsilon:
guess = guess - (((guess**2) - y)/(2*guess))
print(guess)
print('Square root of ' + str(y) + ' is about ' + str(guess))
@nafu
nafu / gist:4944047
Created February 13, 2013 11:39
Bisection Search
x = 1234567
epsilon = 0.01
numGuesses = 0
low = 0.0
high = x
ans = (high + low)/2.0
while abs(ans**2 - x) >= epsilon:
print('low = ' + str(low) + ' high = ' + str(high) + ' ans = ' + str(ans))
numGuesses += 1
if ans**2 < x:
@nafu
nafu / gist:4944095
Created February 13, 2013 11:51
Decimal to Binary
num = 256
if num < 0:
isNeg = True
num = abs(num)
else:
isNeg = False
result = ''
if num == 0:
result = '0'
@nafu
nafu / gist:4952475
Last active December 13, 2015 17:59
Definitions
def a(x, y, z):
if x:
return y
else:
return z
def b(q, r):
return a(q>r, q, r)
print(a(False, 2, 3))