Skip to content

Instantly share code, notes, and snippets.

@toctan
toctan / xclip.rb
Last active December 24, 2015 23:09
Why??
irb(main):001:0> require 'benchmark'
=> true
irb(main):002:0> puts Benchmark.measure { system "xclip .bashrc" }
0.000000 0.000000 0.000000 ( 0.008030)
=> nil
irb(main):003:0> puts Benchmark.measure { `xclip .bashrc` }
0.000000 0.000000 0.000000 ( 33.215158)
=> nil
irb(main):004:0> RUBY_VERSION
=> "2.0.0"
@toctan
toctan / spec_helper.rb
Last active December 25, 2015 01:39
database_cleaner with RSpec
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
alias_method_chain :call, :quiet_assets
end
.topic__node {
@extend .ui.red.label;
@extend .zeta;
position: relative;
left: 1.55rem;
float: right;
margin: 0.2rem 0;
padding: 0 1em 0.1em 0.8em;
border-color: rgba(0, 0, 0, 0.15);
border-radius: 4px 0px 0px 4px;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.shadowsocks</string>
<key>ProgramArguments</key>
<array>
@toctan
toctan / sicp.scm
Last active December 30, 2015 11:29
;; Exercise 1.1
10 ;Value: 10
(+ 5 3 4) ;Value: 12
(- 9 1) ;Value: 8
(/ 6 2) ;Value: 3
@@foo = 'foo'
Object.class_variable_get(:@@foo) # => "foo"
class Bar
def self.foo
@@foo
end
end
(define (lat? l)
(cond ((null? l) #t)
((atom? (car l)) (lat? (cdr l)))
(else #f)))
(define (member? a lat)
(cond ((null? lat) #f)
((eq? a (car lat)) #t)
(else (member? a (cdr lat)))))
@toctan
toctan / sum.scm
Last active December 31, 2015 19:39
(define (sum-int a b)
(if (> a b)
0
(+ a
(sum-int (1+ a) b))))
(define (sum-sq a b)
(if (> a b)
0
(+ (square a)
@toctan
toctan / sqrt.scm
Last active December 31, 2015 19:39
(define (sqrt x)
(define tolerance 0.00001)
(define (good-enough? y)
(< (abs (- (square y) x))
tolerance))
(define (improve y)
(average (/ x y) y))
(define (try y)
(if (good-enough? y)
y