Skip to content

Instantly share code, notes, and snippets.

@AbdallaZaki
AbdallaZaki / gist:ce54ccff95ee1a06236b
Last active August 29, 2015 14:06
Project Euler problem 5
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Algo1
{
internal class Program
#!/bin/bash
cd ~/Downloads
filetounrar=$(ls ./*.rar -t | head -n1)
function unrarmyfile ()
{
rar e "$filetounrar"
}
function userchoose ()
{
echo "[r]eplace [q]uit"
@AbdallaZaki
AbdallaZaki / fixarbicsubtitle.sh
Created February 3, 2016 08:47
fix arabic subtitles
#!bin/bash
dir_name=$1
current_dir=$(pwd)
if [ ! -d $dir_name ];then
echo "not a directory"
exit 1
fi
function change_encoding ()
{
cd $dir_name
def loop dir , parent = Dir.pwd
Dir.entries(dir).each do |e|
if File.directory?(e) && (e!="." && e!="..")
dir_path=File.absolute_path(e ,parent)
puts dir_path
loop dir_path , e
elsif !File.directory?(e) && (e!="." && e!="..")
puts File.absolute_path(e , parent)
end
end
#!/bin/bash
last_video=$(find ~/Downloads -type f -regex ".*\.\(mp4\|mkv\|rmvb\|vob\|flv\|mov\|avi\)$" -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | tail -n1 | grep -o "/home.*$" )
if [ -z "$( pgrep totem )" ]; then
echo "$last_video" | xargs -d "\n" totem &
else
echo "$last_video" | xargs -d "\n" totem
fi
Array.prototype.unShift = function (){
let newArray = [...arguments], i = 0, len = this.length , newArrLength=newArray.length;
for(i; i < len; i++){
newArray[newArrLength+i] = this[i];
}
return newArray;
}
let arr =[1,2];
require 'securerandom'
def get_ips ips_file
content=""
File.open(ips_file,"r") {|file| content = file.read }
result=""
content.scan(/(((([0-9]{1,3}\.){3}[0-9])|(([0-9a-f]{1,4}\:){3}\:))\/[0-9]{2})/) { |match| result += "#{match[0]}\n" }
File.open("#{ips_file}-#{SecureRandom.uuid}.txt","w") {|file| file.write(result)}
end
get_ips ARGV[0]
// https://projecteuler.net/problem=1
var getSumOfMuliples = function (n1,n2,limit){
var result=0;
for(var i=Math.min(n1,n2);i<limit;i++){
if(i%n1==0||i%n2==0){
result+=i;
}
}
return result;
}
// https://projecteuler.net/problem=2
var getSumOfEvenFibonacciNum = function (limit){
var evenNum=2,prevEvenNum=0,sumOfEvenFibonacciNum=evenNum;
while (evenNum<=limit){
var tempEvenNum=evenNum;
evenNum=(evenNum*4)+prevEvenNum;
if(evenNum>limit) break;
prevEvenNum=tempEvenNum;
sumOfEvenFibonacciNum+=evenNum;
}
<?php
class Paging {
public function get_paging_info($row_count, $page_length = 10, $page_num = 1, $max_page_num = 5) {
$count = $row_count;
if ($count == 0) {
return "no data";
}
$page_num = $this->page_num_validation ( $page_num );
$pages_count = $this->pages_count_validation ( ($count / $page_length) );
$offset = $page_length * ($page_num - 1);