Skip to content

Instantly share code, notes, and snippets.

View moski's full-sized avatar

Moski Doski moski

View GitHub Profile
@moski
moski / ruby_unix_color.rb
Created May 20, 2012 16:48
Printing Colored Text in UNIX Terminals from Ruby
# 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
@moski
moski / ruby-hearts.rb
Created May 20, 2012 16:16
Drawing hearts using ruby
#!/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:
@moski
moski / voice2voice.rb
Created February 5, 2012 17:06
An Engine to translate voice input files between languages. http://blog.moski.me/2012/02/building-siri-arabic-support-arabic.html
# 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
@moski
moski / speakit.rb
Created February 5, 2012 15:46
A small function to call Google tts service and speak a text. http://blog.moski.me/2012/02/building-siri-arabic-support-arabic.html
# 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
@moski
moski / google_trasnlate.rb
Created February 5, 2012 13:45
A module to translate text using the google translate page. http://blog.moski.me/2012/02/building-siri-arabic-support-arabic.html
# 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"
# 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
# => "كم الساعه"
#
# 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)
@moski
moski / bitly_domain_counter.rb
Created January 31, 2012 21:49
How many domains are using Bitly as a shortener service ?
# 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"
@moski
moski / bitly_domains.js
Created January 31, 2012 21:29
How many domains are using Bitly as a shortener service ?
// 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",
@moski
moski / addLoadingLabel-removeLoadingLabel.coffee
Created January 31, 2012 18:22
Disabling the submit button and changing the label with Jquery.
# 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