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 Regexp | |
| def to_javascript | |
| Regexp.new(inspect.sub('\\A','^').sub('\\Z','$').sub('\\z','$').sub(/^\//,'').sub(/\/[a-z]*$/,'').gsub(/\(\?#.+\)/, '').gsub(/\(\?-\w+:/,'('), self.options).inspect | |
| end | |
| end |
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
| cd ~/Code/repo/ && watch -c 'ls .git/index.lock 2>/dev/null || git status --short' |
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
| enc = '# -*- encoding : utf-8 -*-' | |
| `git ls-files -- spec | xargs head -1 | grep -v encoding`. | |
| split("\n\n"). | |
| reject{|l| l !~ /\n/}. | |
| map{|l| l.split("\n").first}. | |
| map{|f| f[/^==> (.*) <==$/, 1]}. | |
| each{|f| | |
| system "echo '#{enc}' > tempfile && cat #{f} >> tempfile && mv tempfile #{f}" | |
| } |
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
| # -*- encoding : utf-8 -*- | |
| require "spec_helper" | |
| require "set" | |
| # Reads requests from test/fixtures/logs/requests.log and builds examples that | |
| # test if the requests are routable. | |
| # | |
| # The syntax it understands is (same as `haproxy.log`): | |
| # {www.skroutz.gr} "POST /shops/add_review/984?some=other" | |
| # |
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 StaticsController < ActionController::Base | |
| def render_404 | |
| if real_404? | |
| send_detailed_disaster_mail(request) | |
| end | |
| respond_to do |format| | |
| format.json do | |
| render json: "", status: 404 | |
| end |
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
| if @user.try(:can_edit_post?) | |
| # do something | |
| end |
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
| -- Prints the variable (even a table) in detail. It is very useful for tables | |
| -- where print() is more or less useless. | |
| function inspect(variable, indentation) | |
| local inspected = "" -- this will be printed at the end | |
| local inner_indentation = indentation and indentation + 1 or 0 -- for nested tables | |
| local tabs = "" -- also for nested tables | |
| for i=1,inner_indentation do | |
| tabs = tabs .. "\t" | |
| end |
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 Animal | |
| def speak | |
| puts "..." | |
| end | |
| end | |
| class Cat < Animal | |
| def speak | |
| puts "Mew..." | |
| end |
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
| $ git status | |
| # On branch my-branch | |
| # Changes not staged for commit: | |
| # (use "git add <file>..." to update what will be committed) | |
| # (use "git checkout -- <file>..." to discard changes in working directory) | |
| # | |
| # modified: db/schema.rb | |
| # | |
| no changes added to commit (use "git add" and/or "git commit -a") | |
| $ git diff |
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 MyTimerClass | |
| attr_reader :timers | |
| def initialize | |
| @timers = {} | |
| @parent_timer = nil | |
| end | |
| def clock!(name, &block) | |
| @timers[name] ||= 0 |