Skip to content

Instantly share code, notes, and snippets.

def resolve(string)
string.gsub(/\d\[(.*?)\]/){|a|
formated = a.split("[")[1..-1].join("[")
if formated.include?('[')
resolve(formated) * a.split("[").first.to_i
else
a.split("[").last * a.split("[").first.to_i
end
}.gsub("]", "")
class Matrix
def &(matrix)
Matrix.Raise ErrDimensionMismatch, "Matrix dimension mismatch" unless (row_count == matrix.row_count && column_count == matrix.column_count)
rows = Array.new(row_count) {|i|
Array.new(column_count) {|j|
self[i, j] & matrix[i, j]
}
}
new_matrix rows, matrix.column_count
end
@abo-elleef
abo-elleef / flatten.js
Created April 6, 2017 07:10
flatten#js
function flatten(set, seen){
var seen = seen ? seen : [];
for(var i=0; i<set.length; i++){
if(Array.isArray(set[i])){
flatten(set[i],seen)
}else{
seen.push(set[i])
}
}
@abo-elleef
abo-elleef / fromG2H.rb
Last active December 16, 2015 16:58
it is a ruby converter from Gregorian to Hijure date format , Hijure date in the formal date in many Arabic and Islamic countries
# you can change the variable given_date to the date you want to be converted or run it directory form terminal like so
#ruby filename.rb year month day
#duby filename.rb 2000 1 1
require "date"
arabic_months = {
1 => "Muharam",
require "net/imap"
require "mail"
def connect_to_mail_server (username , password,server ="imap.google.com",post=993,ssl=true)
imap = Net::IMAP.new(server,port,ssl)
imap.login(username,password)
return imap
end
def get_access_to_mail_boxes imap
@abo-elleef
abo-elleef / gist:5251706
Created March 27, 2013 04:45
try to get around Error: $digest already in progress in my first angular js app with rails backend
in angular js app
After sending delete request to your backend server it will be redirected by default to the otherwise url that you define to in the app.js file
so if you try to redirect after delete request using
$location.path ("URL");
or
$scope.$apply($location.path("URL"));
or
$scope.$apply($location.path("URL"));
Error: $digest already in progress