Skip to content

Instantly share code, notes, and snippets.

@paractmol
paractmol / gspeech.rb
Created October 19, 2012 10:55
Google Speech
# encoding: UTF-8
#
# Example of usage:
# 1.9.3p125 :003 > t = GoogleSpeech.load "#{Dir.home}/text.txt"
# => #<GoogleSpeech:0x007f89e38ba690 @text="Hello World it's just a text file. Hey yey!!!", @lang="en">
# 1.9.3p125 :004 > t.save("out.mp3")
# => "out.mp3"
#
# 1.9.3p125 :005 > f = GoogleSpeech.new "Thats shit but I love it"
@paractmol
paractmol / gist:4369670
Created December 24, 2012 15:35
Google Translation.
# encoding: UTF-8
#
#1.9.3-p327 :013 > t = GTranslate.new "This stuff is pretty unexpected!", "pl"
#=> #<GTranslate:0x0000000195b0b8 @lang="pl", @text="This stuff is pretty unexpected!", @response=["[[[\"Ten materiał jest dość nieoczekiwanego!\",\"This stuff is pretty unexpected!\",\"\",\"\"]],,\"en\",,[[\"Ten materiał jest\",[5],1,0,802,0,3,0],[\"dość\",[6],1,0,792,3,4,0],[\"nieoczekiwanego!\",[7],1,0,726,4,6,0]],[[\"This stuff is\",5,[[\"Ten materiał jest\",802,1,0],[\"Tych rzeczy jest\",0,1,0],[\"Te rzeczy są\",0,1,0]],[[0,13]],\"This stuff is pretty unexpected!\"],[\"pretty\",6,[[\"dość\",792,1,0],[\"całkiem\",9,1,0],[\"pretty\",0,1,0],[\"śliczny\",0,1,0],[\"ładna\",0,1,0]],[[14,20]],\"\"],[\"unexpected !\",7,[[\"nieoczekiwanego!\",726,1,0]],[[21,32]],\"\"]],,,[[\"en\"]],28]"]>
#1.9.3-p327 :014 > t.parse[0]
# => ["Ten materiał jest dość nieoczekiwanego!"]
#
class GTranslate
require 'net/http'
@paractmol
paractmol / linked_list.rb
Last active August 29, 2015 14:13
linked_list.rb
class Node
attr_accessor :next_item, :value
def initialize(next_item, value)
@next_item = next_item
@value = value
end
def reversed
@a = []
@paractmol
paractmol / custom_max.rb
Created January 21, 2015 11:18
custom_max.rb
class Array
def custom_max
idx = self[0] > self[1] ? 1 : 0
self.delete_at(idx)
self.length <= 1 ? self[0] : self.custom_max
end
end
a = [4,3,6,1,44,4,8,31,41,2,1,98,2,3,1,8,32,1,4,5,6]
class Collection
class Instance
def initialize(id)
@id = id
end
def say
"I am #{@id}"
end
end
# Adding RMagick to combine images
require 'open-uri'
require 'uri'
require 'rmagick'
class PhotoDownloader
RESOURCE = 'http://access.nypl.org/image.php/'
def initialize(id, zoom, dimension)
@paractmol
paractmol / downloads_ny_photos_step_1.rb
Created October 16, 2016 03:23
downloads_ny_photos_step_1
# First quick draft
require 'open-uri'
require 'uri'
class PhotoDownloader
RESOURCE = 'http://access.nypl.org/image.php/'
def initialize(id, dimension)
@id = id
# Adding RMagick to combine images
require 'open-uri'
require 'uri'
require 'rmagick'
class PhotoDownloader
RESOURCE = 'http://access.nypl.org/image.php/'
def initialize(id, zoom, dimension)
require 'open-uri'
class Bingy
LANDING_PAGE = 'http://www.bing.com/translator'.freeze
SPEAK_URL = LANDING_PAGE + '/api/language/Speak?locale=en-US&media=audio/mp3'
def initialize(text, gender = 'male')
@user_agent = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
@params = { text: text, gender: gender }
end
require 'twitter'
# Bot implementation
class Complimentator
# Module that holds all commands
module Command
def compliment(tweet)
update(tweet, @compliments.sample)
end