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 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 |
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
| 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" |
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
| require 'thread' | |
| QUEUE_SIZE = 2 | |
| POOL_SIZE = 5 | |
| queue = SizedQueue.new(QUEUE_SIZE) | |
| producers = POOL_SIZE.times.map do | |
| Thread.new do | |
| item = rand(10) |
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
| # lib/tasks/pg.rake | |
| namespace :pg do | |
| desc "Dumps the database to backups" | |
| task :dump => :environment do | |
| cmd = nil | |
| with_config do |app, host, db, user| | |
| cmd = "pg_dump -h #{host} -d #{db} -U #{user} -Ft -v -c -f #{Rails.root}/public/resources/duoduo/db_backup/#{Time.now.strftime("%Y%m%d%H%M%S")}_#{db}.tar" | |
| end | |
| puts cmd | |
| exec cmd |
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
| # In Ruby, we can just use Array#flatten | |
| # | |
| # def flatten(array) | |
| # array.flatten | |
| # end | |
| # In case you want a manmade version | |
| def flatten(array) | |
| array.reduce([]) do |res, element| | |
| Array === element ? res += flatten(element) : res << element |
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
| #!/usr/bin/env ruby | |
| # Usage | |
| # | |
| # echo 'client list' | redis-cli -h $HOST -p $PORT | ./redis_client_ip.rb | |
| # | |
| # Reference | |
| # | |
| # http://www.jstorimer.com/blogs/workingwithcode/7766125-writing-ruby-scripts-that-respect-pipelines | |
| # http://redis.io/commands/client-list |
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 Html exposing (..) | |
| import Html.Attributes exposing (..) | |
| import Html.Events exposing (..) | |
| import Html.App as Html | |
| -- model | |
| type alias Model = | |
| { | |
| shelves : Int, |
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
| port module Main exposing (..) | |
| import Html exposing (..) | |
| import Html.Events exposing (..) | |
| main = | |
| program | |
| { init = init | |
| , view = view |
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
| # Use a max heap to sort an array | |
| def heap_sort!(array) # Use ! to represent inplace | |
| # setup | |
| n = array.length | |
| array.unshift nil | |
| # build | |
| (n/2).downto(1) do |k| | |
| sink(array, k, n) | |
| 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
| <div id="errors" style=" | |
| background: #c00; | |
| color: #fff; | |
| display: none; | |
| margin: -20px -20px 20px; | |
| padding: 20px; | |
| white-space: pre-wrap; | |
| "></div> | |
| <div id="container"></div> | |
| <script> |