This file contains 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
threads = [] | |
5.times do | |
threads << Thread.new { | |
p require 'date' | |
} | |
end | |
threads.each(&:join) |
This file contains 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
autoload :Date, 'date' | |
module Kernel | |
alias_method :original_require, :require | |
def require(path) | |
puts "Require invoked for #{path}" | |
original_require(path).tap do |loaded| | |
if loaded |
This file contains 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 'find' | |
require 'ptools' | |
frequencies = Hash.new(0) | |
Find.find('.') do |path| | |
basename = File.basename(path) | |
if basename.start_with?('.') | |
Find.prune if basename == '.git' |
This file contains 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 std/[os,setutils] | |
const | |
markerLen = 4 | |
let datastream = readFile(paramStr(1)) | |
for i in 0 .. (high(datastream) - markerLen): | |
let chunk = datastream[i ..< i + markerLen] | |
if chunk.toSet.card == markerLen: |
This file contains 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 std/[os,sequtils,strutils] | |
type | |
Assingment = tuple[fromSection, toSection: uint] | |
func toAssingment(rangeStr: string): Assingment = | |
let pair = rangeStr.split('-') | |
result.fromSection = parseUInt(pair[0]) | |
result.toSection = parseUInt(pair[1]) |
This file contains 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 std/[os,sequtils,sets,sugar] | |
type | |
Rucksack = object | |
compA: HashSet[char] | |
compB: HashSet[char] | |
func toRucksack(rucksackStr: string): Rucksack = | |
let items = distribute(rucksackStr.toSeq, 2) | |
result.compA = items[0].toHashSet |
This file contains 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 std/os | |
type | |
Shape = enum Rock, Paper, Scissors | |
GameResult = range[-1..1] | |
func toShape(shapeChr: char): Shape = | |
case shapeChr: | |
of 'A', 'X': Rock | |
of 'B', 'Y': Paper |
This file contains 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 std/os | |
import std/strutils | |
var max = 0 | |
var partial = 0 | |
for line in lines(paramStr(1)): | |
if len(line) != 0: | |
partial += parseInt(line) | |
else: |
This file contains 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
module Simulation | |
# Clocks in a Linux system | |
# ======================== | |
# | |
# A Linux system has two clocks: The hardware clock, and the system clock. | |
# | |
# The hardware clock, also known as RTC or real-time clock, is a physical | |
# clock. This clock runs always, even when the system is shut down or | |
# unplugged the clock keeps running because it has an independent source of | |
# power, normally a lithium battery. See |
This file contains 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
n = 3004953 | |
start = n/2 + 1 | |
play = [*start..n, *1...start] | |
while n > 1 | |
play.shift | |
play << play.shift if n.odd? | |
n -= 1 | |
end |
NewerOlder