Skip to content

Instantly share code, notes, and snippets.

View mshirdel's full-sized avatar
🏠
Working from home

Meysam Shirdel mshirdel

🏠
Working from home
View GitHub Profile
@mshirdel
mshirdel / GetQueryString
Created August 28, 2016 06:10
Get query string in js
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
@mshirdel
mshirdel / add_rvm_to_terminator
Created July 6, 2016 13:58
Terminator could not find rails!
source ~/.rvm/scripts/rvm
android create project -a Main -k com.example.app -t 19 -g -v 0.10 \
-p AppWithGradleTemplate
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6
@mshirdel
mshirdel / unique_words_with_count.rb
Last active June 18, 2016 12:57
List unique words with count
ARGV.each do |arg|
file = File.open(arg, 'r')
all_words = file.read.split(/\W+/)
all_words_with_count = all_words.inject(Hash.new(0)) { |h, e| h[e] += 1 ; h }
all_words_with_count.sort_by { |_key, value| value }.to_h.each do |word, count|
puts "#{word},#{count}"
end
end
@mshirdel
mshirdel / find_unique_words.rb
Created June 18, 2016 12:42
Find unique words
ARGV.each do |arg|
file = File.open(arg, 'r')
content = file.read.split(/\W+/).uniq # content is Array
end
@mshirdel
mshirdel / runsql.rb
Created June 16, 2016 09:36
Run sqlcmd command with ruby
Dir["./*.sql"].each { |f| system "sqlcmd -S SERVER\INSTANCE -U sa -P PASS -d DBNAME -i #{f}"}
@mshirdel
mshirdel / split
Created June 16, 2016 09:34
Split large files with ruby
PAGE_SIZE = 10000
line_strat = 0
line_end = PAGE_SIZE
file_content = ""
page_number = 1
File.open("data", "r:utf-8").each_line.with_index do |line, index|
if index < line_end && index >= line_strat
File.open "part#{page_number}.sql", "a:utf-8" do |f|
f.write line
end
To delete a local branch
git branch -d the_local_branch
To remove a remote branch (if you know what you are doing!)
git push origin :the_remote_branch
#!/bin/bash
# this script is not written by me. Just using it and sharing it here.
# export DBUS_SESSION_BUS_ADDRESS environment variable useful when the script is set as a cron job
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
# $bing is needed to form the fully qualified URL for