Skip to content

Instantly share code, notes, and snippets.

View Jeweller-Tsai's full-sized avatar

nate Jeweller-Tsai

View GitHub Profile
use std::io::{BufReader,BufRead};
use std::fs::File;
use std::time::Duration;
use std::thread;
use std::env;
fn main() {
fn tail(reader: &mut BufReader<&File>) {
let time = Duration::from_millis(10);
loop {
require 'em-http-request'
require 'em-synchrony'
require 'em-synchrony/em-http'
module Gmusic
# = AsyncRequest
# This module is powered by {EventMachine}[https://github.com/eventmachine/eventmachine] and {em-http-request}[https://github.com/igrigorik/em-http-request] and {em-synchrony}[https://github.com/igrigorik/em-synchrony].
# By taking advantage of EventMacine, it allows you to issue parallel requests. You can easily control concurrency and follow redirects.
#
@Jeweller-Tsai
Jeweller-Tsai / download.rb
Created May 26, 2012 16:06
Using HTTP range to download a file separately
require "net/http"
require 'uri'
def download(uri_str)
uri = URI uri_str
Net::HTTP.new(uri.host, uri.port).start do |http|
head = http.request_head uri.path
length = head.content_length
puts length
@Jeweller-Tsai
Jeweller-Tsai / gist:2436935
Created April 21, 2012 12:45
How to take STDIN in the middle of a method execution?

How to take STDIN in the middle of a method execution?

 #!/usr/bin/env ruby

class CLI < Thor
  def search
    # ...

    selected = gets.chomp.to_i # this will raise: Broken pipe (Errno::EPIPE)