Skip to content

Instantly share code, notes, and snippets.

View forabi's full-sized avatar
🎯
Focusing

M-Fawaz Orabi forabi

🎯
Focusing
View GitHub Profile
app = angular.module "ng-blog", []
app.controller 'HomeCtrl', ($http, $scope) ->
$scope.posts = [
(
title: "Hello world!",
excerpt: "A simple Hello World!"
)
(
title: "Hello world!",
excerpt: "A simple Hello World!"
@forabi
forabi / primes.js
Last active August 29, 2015 14:03
ECMAScript 6 implementation of Sieve of Eratosthenes algorithm https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
'use strict';
function* getPrimes(n) {
let compos = [];
for (let i = 2; i <= n; i++) {
if (compos[i]) continue;
yield i;
for (let j = i * 2; j <= n; j += i) {
compos[j] = true;
}
}
@forabi
forabi / stat.sh
Created September 26, 2014 17:11
Statistics for Node/CoffeeScript projects
#!/bin/bash
function get_file_names {
find -type f |
egrep -v '/(node_modules)|(.git)/' | # Ignore node_modules and .git
egrep -v '^./(tmp|posts|dist)/' | # Ignored dirs
egrep -v '.(swp|ttf|txt|css|woff|eot|svg|png|jpe?g|sublime-.*)$' # Ignored file types
}
function get_loc {
@forabi
forabi / 99-arabic.conf
Created June 14, 2015 18:20
Substitute Linux default font family for Arabic with Helvetica World. Save as /etc/fonts/conf.d/99-arabic.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- $XDG_CONFIG_HOME/fontconfig/fonts.conf for per-user font configuration -->
<fontconfig>
<match>
<test name="lang" compare="contains">
<string>ar</string>
</test>
<test name="family" compare="not_eq">
<string>monospace</string>
@forabi
forabi / ar.json
Created August 29, 2011 19:58 — forked from cramforce/de.json
lang.json
{
"locale": "ar",
"text": {
"#authors": [
{
"name": "Muhammad Fawwaz Orabi",
"screen-name": "forabi"
}
],
"tweet": {
@forabi
forabi / rename.js
Last active December 30, 2015 07:29
var fs = require('fs');
var path = require('path');
fs.readdir(process.cwd(), function(err, files){
var newNames = {};
files.forEach(function(file){
console.log(file);
if (file.match(/.+.txt/i)){
console.log('Found text file', file);
fs.readFile(path.join(process.cwd(), file), 'utf8', function(err, data){
newNames[file] = [];
@forabi
forabi / auto_rtl.js
Last active April 11, 2016 17:50
Fix text direction for RTL articles on Pocket and file previews on GitHub and GitLab
// ==UserScript==
// @name Auto-RTL
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Fixes layout direction (RTL/LTR) for text on various websites
// @author You
// @match https://gitlab.com/*
// @match https://github.com/*
// @match http*://getpocket.com/beta/read/*
// @match http*://getpocket.com/read/*
import java.io.*;
import java.util.*;
import javax.comm.*;
/* الكلاس بتعتمد واجهة Runnable مشان نقدر نشغلها بـThread لحالها>
/ SerialPortEventListener على ما يبدو جاية من حزمة javax.comm
/ بتخلينا نستمع لأي تغيرات على منفذ تسلسلي،
/ يعني لما بصير أي شي على المنفذ، فينا نعمل أي شي،
/ هي بس شغلتا تخبرنا شو صار. */
public class SimpleRead implements Runnable, SerialPortEventListener {
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n"; // الجملة يلي بدنا نكتبها ع المنفذ
static SerialPort serialPort;
static OutputStream outputStream;
@forabi
forabi / pdfcount.sh
Created August 1, 2015 11:29
Get total page count for all PDF files in the current working directory. Requires pdfinfo
#!/bin/bash
num_pages=0;
for file in *.pdf; do
f_pages=$(pdfinfo "$file" 2>/dev/null | grep Pages | cut -d ":" -f 2 | sed -e 's/^[ \t]*//')
if [[ -z $f_pages ]]; then
echo "Error in $file" && exit 1;
fi
num_pages=$(( num_pages + $f_pages ))
done
echo $num_pages;