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 | |
# generate a single sentence from a canonical form | |
# canonical sentence is a multi sentences combined in one | |
# form, generator will generate a sentence from it randomly | |
# based on the form, for example: | |
# "Hello [Emad|Elsaid]" , may generate "Hello Emad" or | |
# "Hello Elsaid" the result is random. | |
# also you could nest [] inside each other to gain a multi level | |
# canonical sentence example: | |
# "[[Hi|Hello] [Emad|elsaid] | good [morning|night] sir]" |
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 'Twitter' #gem install twitter | |
while true | |
begin | |
# Create a read write application from : | |
# https://apps.twitter.com | |
# authenticate it for your account | |
# fill in the following | |
config = { | |
consumer_key: '', | |
consumer_secret: '', |
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 | |
require 'pdf/reader' # gem install pdf-reader | |
# credits to : | |
# https://github.com/yob/pdf-reader/blob/master/examples/text.rb | |
# usage example: | |
# ruby pdf2txt.rb /path-to-file/file1.pdf [/path-to-file/file2.pdf..] | |
ARGV.each do |filename| | |
PDF::Reader.open(filename) do |reader| |
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 'open-uri' | |
require 'json' | |
language = 'en' | |
print 'What do you need to know? : ' | |
article = URI::encode gets.chomp | |
request_url = "http://#{language}.wikipedia.org/w/api.php?action=parse&page=#{article}&format=json&prop=text§ion=0" |
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 | |
require 'koala' # gem install koala --no-document | |
require 'json' | |
# create a facebook app and get access token from here | |
# https://developers.facebook.com/tools/explorer | |
# select "user_friends" when authenticating | |
oauth_access_token = 'xxxxxxxxxxxxxxxx' | |
graph = Koala::Facebook::API.new(oauth_access_token) | |
fields = 'bio,name,birthday,first_name,last_name,gender,hometown,relationship_status,username,website,languages' |
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 | |
# gem install sinatra --no-document | |
# gem install github-markdown --no-document | |
require 'sinatra' | |
require 'github/markdown' | |
set :port, 3000 | |
get '/' do | |
<<-EOT | |
<!DOCTYPE html> |
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 'time' | |
Date_of_birth = '1988-8-31' | |
# Credit to : http://stackoverflow.com/questions/4136248/how-to-generate-a-human-readable-time-range-using-ruby-on-rails | |
# and modified a little bit | |
def humanize secs | |
[ | |
[60, :seconds], | |
[60, :minutes], |
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
func ago(t time.Duration) (o string) { | |
const day = time.Hour * 24 | |
const week = day * 7 | |
const month = day * 30 | |
const year = day * 365 | |
const maxPrecision = 2 | |
if t.Seconds() < 1 { | |
return "seconds ago" | |
} |
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 | |
# Author : Emad Elsaid (https://github.com/blazeeboy) | |
FILENAME = 'db.txt' | |
OPEN, CLOSE = 1 , 0 | |
file = File.open(FILENAME, 'a') | |
file.write "#{OPEN} : #{Time.new}\n" | |
file.flush | |
begin |
NewerOlder