http://stackoverflow.com/questions/3512471/non-capturing-group
str = "http://stackoverflow.com/questions/tagged/regex"
str =~ /(http|ftp):\/\/([^\/\r\n]+)(\/[^\r\n]*)?/
puts $1 # => http
# with ?:
require 'logger' | |
# Examples | |
# | |
# logger = DistinctFileLogger.new(STDOUT) | |
# logger.set_error_path('/Users/wendi/tmp/logger/error.log') | |
# logger.info "processing: 1/10" | |
# logger.info "processing: 2/10" | |
# logger.info "processing: 3/10" |
class MultiLevelPageTable | |
PAGE_DIRECTORY_BASE_REGISTER = 108 | |
# Save all intermedial state in binary string | |
attr_reader :pages, :virtual_address, | |
:page_directory_index, :page_table_index, :offset, | |
:page_directory, :page_directory_entry, :page_frame_number, | |
:page_table, :page_table_entry, :physical_frame_number, | |
:physical_address, :value |
http://stackoverflow.com/questions/3512471/non-capturing-group
str = "http://stackoverflow.com/questions/tagged/regex"
str =~ /(http|ftp):\/\/([^\/\r\n]+)(\/[^\r\n]*)?/
puts $1 # => http
# with ?:
from http://blog.honeybadger.io/advanced-ruby-hash-techniques/
h = Hash.new { |hash, key| raise ArgumentError.new("No hash key: #{ key }") }
h[:a]=1
h[:a] # 1
h[:x] # raises ArgumentError: No hash key: x
csrf.js
var csrftk = $("meta[name='csrf-token']").attr("content");
// Ajax set
$(document).ajaxSend(function(e, xhr, options) {
xhr.setRequestHeader("X-CSRF-Token", csrftk);
});
# API | |
# | |
# + push | |
# + top | |
# + pop | |
# + empty | |
# + empty? | |
ArrayStack = Struct.new(:values) do | |
def push(value) |
There is a weird situation I haven't noticed before:
class Counter
attr_accessor :processed, :processed_names
def initialize
@processed = 0
@processed_names = []
end
git filter-branch -f --commit-filter ' | |
if [ "$GIT_COMMITTER_NAME" = "<Old name>" ]; | |
then | |
GIT_COMMITTER_NAME="<New name>"; | |
GIT_COMMITTER_EMAIL="<New email>"; | |
GIT_AUTHOR_NAME="<New name>"; | |
GIT_AUTHOR_EMAIL="<New email>"; | |
else | |
git commit-tree "$@"; | |
fi' -- --all |
HOST = "" | |
APP_KEY = "" | |
APP_SECRET = "" | |
REQUEST_TOKEN = "" | |
REQUEST_TOKEN_SECRET = "" | |
REQUEST_TOKEN_VERIFIER = "" | |
ACCESS_TOKEN = "" | |
ACCESS_TOKEN_SECRET = "" |
from Binary and Bitwise Operations in Ruby by CooperPress http://goo.gl/4uQY7f
How to represent base 2, 8, 10, 16 in Integer?