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
# How to invoke a picker in your code to select items interactively. | |
PICKER = 'fzf' | |
PICKER_OPTS = '-m' # allow multiple selection | |
def picker(prog, entries) | |
in_ary = entries.map(&:to_s) | |
IO.popen(prog, "r+") { |pipe| | |
in_ary.each {|e| pipe.puts(e)} | |
pipe.close_write |
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
# | |
# Which implementation do you prefer? | |
# | |
# 1. | |
def exist_in_search_path_1?(file, paths) | |
paths.split(":").each { |dir| | |
return true if FileTest.exist?(File.expand_path(file, dir)) | |
} | |
false |
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
#!/usr/bin/env ruby -w | |
# -*- coding: utf-8 -*- | |
# Print size of specified file(s) friendly and nicely for human beings | |
require 'optparse' | |
Version = '0.3.2' | |
Release = '2017-04-28' |
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 <Foundation/Foundation.h> | |
// convert a RFC3399 date (& time) into a NSDate object | |
// NOTE: This function ignores fractions of a second in the RFC3339 | |
// representation. | |
NSDate *getDateObject(NSString *rfc3339) | |
{ | |
// Date and Time representation in RFC3399: | |
// Pattern #1: "YYYY-MM-DDTHH:MM:SSZ" | |
// 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
#!/opt/local/bin/ruby1.9 -w | |
# -*- coding: utf-8 -*- | |
# listprimes_sieve.rb: make a list of prime numbers using the sieve of Eratosthenes | |
start = ARGV.shift.to_i | |
start = 2 if start < 2 | |
range = ARGV.shift.to_i | |
def sieve(start, range) | |
limit = start + range |
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
#!/opt/local/bin/ruby1.9 -w | |
# -*- coding: utf-8 -*- | |
# listprime.rb: make a list of prime numbers. | |
require 'prime' | |
def die(*x) | |
STDERR.puts x | |
exit 1 | |
end |
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
#!/opt/local/bin/ruby1.9 -w | |
# -*- coding: utf-8 -*- | |
# listprimes_binsearch.rb: make a list of prime numbers. | |
def die(*x) | |
STDERR.puts x | |
exit 1 | |
end | |
if ARGV.length < 2 |
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
#!/opt/local/bin/ruby1.9 -w | |
# -*- coding: utf-8 -*- | |
# checkprimes.rb: check each prime in primes.txt | |
PRIMES_FILE = "primes.txt" | |
$primes = [] | |
if File.exist?(PRIMES_FILE) | |
File.foreach(PRIMES_FILE) do |line| | |
$primes.push(line.to_i) |
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
#!/opt/local/bin/ruby1.9 -w | |
# -*- coding: utf-8 -*- | |
# listprimes.rb: make a list of prime numbers. | |
def die(*x) | |
STDERR.puts x | |
exit 1 | |
end | |
if ARGV.length < 2 |
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
class RequestHistory(object): | |
def __init__(self, size=10): | |
self.size = size | |
self.modulus = self.size + 1 | |
self.history = [''] * (self.modulus) | |
self.base = 0 | |
self.top = 1 | |
def is_empty(self): | |
return self.base == self.decrement(self.top) |
NewerOlder