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
# encoding: utf-8 | |
class AskForCredentials | |
attr_reader :email, :password | |
def initialize | |
ask_for_credentials | |
end | |
private |
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
# Return the longest path prefix (taken character-by-character) that is a prefix of all paths in array. | |
# If array is empty, return the empty string (''). | |
# Note that this may return invalid paths because it works a character at a time. | |
# | |
def common_prefix(m) | |
# Given a array of pathnames, returns the longest common leading component | |
return '' if m.empty? | |
s1, s2 = m.min, m.max | |
s1.each_char.with_index do |c, i| | |
return s1[0...i] if c != s2[i] |
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
module Sinatra | |
module Flash | |
module Style | |
def styled_flash(key=:flash) | |
return "" if flash(key).empty? | |
id = (key == :flash ? "flash" : "flash_#{key}") | |
close = '<a class="close" data-dismiss="alert" href="#">×</a>' | |
messages = flash(key).collect {|message| " <div class='alert alert-#{message[0]}'>#{close}\n #{message[1]}</div>\n"} | |
"<div id='#{id}'>\n" + messages.join + "</div>" | |
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
require 'net/http' | |
email = '[email protected]' | |
pass = 'secret' | |
client_id = '1234567' | |
scope = 'friends,audio' | |
redirect_uri = 'http://oauth.vk.com/blank.html' | |
display = 'wap' | |
response_type = 'code' |
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
# encoding: utf-8 | |
require 'pp' | |
require 'mechanize' | |
require 'nokogiri' | |
user = '103900' | |
password = '***' | |
agent = Mechanize.new do |a| |
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
# encoding: utf-8 | |
require 'sinatra' | |
require 'slim' | |
require 'data_mapper' | |
require 'carrierwave' | |
require 'carrierwave/datamapper' | |
class ImageUploader < CarrierWave::Uploader::Base |
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
I, [2012-05-17T14:06:40.816605 #2480] INFO -- : Net::HTTP::Get: / | |
D, [2012-05-17T14:06:40.817531 #2480] DEBUG -- : request-header: accept => */* | |
D, [2012-05-17T14:06:40.818051 #2480] DEBUG -- : request-header: user-agent => Mechanize/2.5.1 Ruby/1.9.3p125 (http://github.com/tenderlove/mechanize/) | |
D, [2012-05-17T14:06:40.818556 #2480] DEBUG -- : request-header: accept-encoding => gzip,deflate,identity | |
D, [2012-05-17T14:06:40.819057 #2480] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7 | |
D, [2012-05-17T14:06:40.819613 #2480] DEBUG -- : request-header: accept-language => en-us,en;q=0.5 | |
D, [2012-05-17T14:06:40.820090 #2480] DEBUG -- : request-header: host => google.com | |
I, [2012-05-17T14:06:41.150941 #2480] INFO -- : status: Net::HTTPMovedPermanently 1.1 301 Moved Permanently | |
D, [2012-05-17T14:06:41.151576 #2480] DEBUG -- : response-header: location => http://www.google.com/ | |
D, [2012-05-17T14:06:41.152028 #2480] DEBUG -- : response-header: content-type => text/html; charset=UTF-8 |
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
# -*- encoding: utf-8 -*- | |
require 'date' | |
class BirthdayCountdown | |
# Cache @month, @day and @year on initialization | |
def initialize(month, day, zone = '+00:00') | |
@birthday_month = month | |
@birthday_day = day | |
@zone = zone |
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
# -*- encoding: utf-8 -*- | |
require 'sinatra' | |
require 'slim' | |
set :server, 'thin' | |
connections = [] | |
get '/' do | |
halt slim(:login) unless params[:user] |
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
# -*- encoding: utf-8 -*- | |
#http://en.wiktionary.org/wiki/Index:Chinese_radical | |
ua_cn = { | |
'а' => '开', | |
'б' => '石', | |
'в' => '阝', | |
'г' => '厂', | |
'ґ' => '广', |