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
| # Extend the Ruby String to support coloring | |
| # usage: | |
| # puts "geeks rule".red | |
| # puts "geeks rule".random_color | |
| # blog post http://blog.moski.me/2012/05/drawing-hearts-in-ruby.html | |
| # | |
| class String | |
| def red(); colorize(self, "\033[31m"); end | |
| def green(); colorize(self, "\033[32m"); end | |
| def yellow(); colorize(self, "\033[33m"); 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
| #!/usr/bin/ruby | |
| # some constants used in this app. | |
| MIN = 7 # is the minimum odd number we can use | |
| MAX = 49 # is the maximum odd number we can use | |
| SLEEP_ANIMATION = 0.5 | |
| # Extend the Ruby String to support coloring | |
| # inspired from http://craiccomputing.blogspot.com/2010/08/printing-colored-text-in-unix-terminals.html | |
| # usage: |
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 | |
| # | |
| # @Details: blog post http://blog.moski.me/2012/02/building-siri-arabic-support-arabic.html | |
| # @Install: | |
| # Make sure to have FFMPEG installed using | |
| # brew install ffmpeg or ports install ffmpeg | |
| # | |
| # Install the dependencies | |
| # gem install speech2text |
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
| # blog post http://blog.moski.me/2012/02/building-siri-arabic-support-arabic.html | |
| # Usage: | |
| # speakIt("hello world") | |
| # | |
| # Generate a random filename. | |
| def rand_string(size=20) | |
| chars = ("a".."z").to_a + ("1".."9").to_a | |
| str = Array.new(size, '').collect{chars[rand(chars.size)]}.join |
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
| # blog post http://blog.moski.me/2012/02/building-siri-arabic-support-arabic.html | |
| # Usage: | |
| # translator = Google::Translator.new | |
| # out = translator.translate(:en, :ar, "hello world").first | |
| # => "مرحبا العالم" | |
| # | |
| # out1 = translator.translate(:ar, :en, out).first | |
| # => "Hello world" |
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
| # blog post http://blog.moski.me/2012/02/building-siri-arabic-support-arabic.html | |
| # You can download a sample audio file("time.wav") from here: http://cl.ly/2d220o0I0n2q0H022K0A | |
| # | |
| # Usage: | |
| # audio = Speech::AudioToText.new("./time.wav") | |
| # text = audio.to_text('ar')["hypotheses"].first.first | |
| # => "كم الساعه" | |
| # |
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
| # Lets Monkey patch the speech2text ruby gem https://github.com/taf2/speech2text to support languages | |
| module Speech | |
| class AudioToText | |
| def to_text(lang="ar") | |
| url = "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=speech2text&lang=#{lang}&maxresults=2" | |
| splitter = Speech::AudioSplitter.new(file,300) # based off the wave file because flac doesn't tell us the duration | |
| easy = Curl::Easy.new(url) | |
| splitter.split.each do|chunk| | |
| chunk.build.to_flac | |
| convert_chunk(easy, chunk) |
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
| # blog post http://blog.moski.me/2012/01/how-many-domains-are-using-bitly-as.html | |
| #!/usr/local/bin/ruby | |
| require "rubygems" | |
| require "httparty" | |
| class Bitly | |
| include HTTParty | |
| base_uri "api.bitly.com" |
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
| // blog post http://blog.moski.me/2012/01/how-many-domains-are-using-bitly-as.html | |
| // How many domains are using Bitly as a shortener service ? | |
| var M = "http://api.bitly.com", | |
| N = { | |
| shorten: "/v3/shorten", | |
| expand: "/v3/expand", | |
| info: "/v3/info", | |
| auth: "/v3/authenticate", |
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
| # blog post http://blog.moski.me/2012/01/disabling-submit-button-and-changing.html | |
| $.fn.extend | |
| addLoadingLabel: () -> | |
| # Find the submit button with the following ciritira: | |
| # 1. Has data-loading attribute. | |
| # 2. Not Disabled. | |
| @find(":submit[data-loading]:not(:disabled)").each (a,b) -> | |
| b = $(b) | |
| # Save the original Val |