Skip to content

Instantly share code, notes, and snippets.

View arashm's full-sized avatar
:shipit:

Arash Mousavi arashm

:shipit:
View GitHub Profile
@arashm
arashm / rbenv_migrate_gems.sh
Created February 3, 2013 09:31
migrate GEMs from rbenv cache to the newer version of ruby (without internet) Thanks to Austin Ziegler - http://stackoverflow.com/questions/13649241/copying-gems-from-previous-version-of-ruby-in-rbenv
#!/bin/sh
# if you're using ZSH, change the shebang above to "#!/bin/zsh -i"
if [ ${#} -ne 2 ]; then
echo >&2 Usage: $(basename ${0}) old-version new-version
exit 1
fi
home_path=$(cd ~; pwd -P)
old_version=${1}
@arashm
arashm / en2fa.js
Last active December 17, 2015 23:08 — forked from bahar-Agi/en2fa.js
#Javascript
/*
* English digit to persian
* Copyright(C) 2009 by Amin Akbari [ http://eAmin.me/ ]
* Licensed under the MIT Style License [http://www.opensource.org/licenses/mit-license.php]
*
*/
String.prototype.toFaDigit = function() {
return this.replace(/\d+/g, function(digit) {
var ret = '';
@arashm
arashm / IranElection.rb
Last active December 18, 2015 13:10
Script to Report Iran Election Results (2013) Every 1 Minute
# /usr/bin/env ruby
# if you have "rufus-scheduler" gem installed you can uncomment corresponding lines in order to
# run the script in every certain time.
# require 'rufus/scheduler'
require 'open-uri'
class Election
VALUES = %w{Rohani Qalibaf Rezaei Jalili Velayati Qarazi }
@arashm
arashm / pre-commit.sh
Created July 12, 2013 18:17
If you want to make sure that all of your JS code stays compliant to the style defined in your .jshintrc, you can set the following contents to your .git/hooks/pre-commit file, which is then run each time you try to commit any new of modified files to the project http://seravo.fi/2013/javascript-the-winning-style
#!/bin/bash
# Pre-commit Git hook to run JSHint on JavaScript files.
#
# If you absolutely must commit without testing,
# use: git commit --no-verify
filenames=($(git diff --cached --name-only HEAD))
which jshint &> /dev/null
if [ $? -ne 0 ];
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://wallbase.cc/toplist'))
doc.css('div.wrapper a img').each_with_index do |img, i|
image_name = img['data-original'].split('-').last
link = "http://wallpapers.wallbase.cc/rozne/wallpaper-#{image_name}"
puts "Downloadin Wallpaper #{i}: #{image_name}"
#!/usr/bin/env ruby
require 'cinch' # gem install cinch
require 'wolfram-alpha' # gem install wolfram-alpha
options = { "format" => "plaintext" }
APP_ID = 'XXXXXXXXXXXXXXXX' # get your AppID from http://products.wolframalpha.com/api
client = WolframAlpha::Client.new APP_ID, options
bot_name = 'WolframBot'
bot = Cinch::Bot.new do
#!/usr/bin/env ruby
require 'nokogiri' # gem install nokogiri --no-document
require 'net/http'
require 'json'
require 'cgi'
# Suppose you want to know how to format a date in bash. Why open your browser and read through
# blogs (risking major distraction) when you can simply stay in the console and ask howdoi:
# $ ruby howdoi.rb format date bash
# > DATE=`date +%Y-%m-%d`
@arashm
arashm / redis_pub_sub.rb
Last active March 7, 2024 15:05
A simple chat app to demonstrate a pub/sub system using Redis and Server-Sent Event(SSE). You can see if you open two browsers, both browsers will get updates when user submits a message.
#!/usr/bin/env ruby
# A simple chat app to demonstrate a pub/sub system using
# Redis and Server-Sent Event(SSE)
require 'sinatra'
require 'sinatra/streaming'
require 'redis'
require 'json'
set :port, 3000
html = <<-EOT
@arashm
arashm / soundcloud.rb
Created April 8, 2014 18:53
Simple script to downoad MP3 files from SoundCloud via WGet
#!/usr/bin/env ruby
require 'uri'
require 'httparty'
# Download mp3 files from SoundCloud
# Usage:
# ./soundcloud.rb https://soundcloud.com/tara-tiba/paeez_tara-tiba
class SoundCloud
include HTTParty
base_uri 'https://soundcloud.com'
@arashm
arashm / radiojavan.rb
Last active April 22, 2022 20:03
Fetch download links of RadioJavan Playlists
#!/usr/bin/env ruby
# gem install mechanize
require 'mechanize'
abort "Usage:\n\tradiojavan.rb \"https://www.radiojavan.com/playlists/playlist/mp3/02596ef9986a\" output_txt" if ARGV.size < 2
playlist_url = ARGV[0]
output_file = ARGV[1]
HOST = 'https://www.radiojavan.com'