Skip to content

Instantly share code, notes, and snippets.

@amrza
amrza / infix.kt
Created Nov 2, 2018
fun with infix funs in kotlin
View infix.kt
import Foods.*
import Sports.*
import Superpowers.*
enum class Foods { pizza, fesenjoon }
enum class Sports { football, volleyball }
enum class Superpowers { fly, disappear }
data class Person(val name: String)
infix fun Person.like(food: Foods) = println("${name} likes ${food}.")
@amrza
amrza / fa.en.numbers.js
Last active Jun 22, 2018
Convert numbers to FA/EN [alternative]
View fa.en.numbers.js
/**
* Convert English numbers to Persian.
*
* @param {string} value
* @return {string} converted string.
*/
function faNumbers(value) {
if (typeof value === "number") {
var value = value.toString();
}
@amrza
amrza / fa.en.numbers.js
Last active Oct 7, 2020
Convert numbers to FA/EN
View fa.en.numbers.js
/**
* Convert English numbers to Persian.
*
* @param {string} value
* @return {string} converted string.
*/
function faNumbers(value) {
var englishNumbers = {
'0': '۰', '1': '۱', '2': '۲', '3': '۳', '4': '۴',
'5': '۵', '6': '۶', '7': '۷', '8': '۸', '9': '۹'
View cal-jalaali-2.js
function between(number, start, end) {
return number >= start && number <= end;
}
function makeWidth(day) {
if (between(day, 1, 9)) { return day + " " }
if (between(day, 10, 31)) { return day + " " }
return " ";
}
View cal-jalaali.js
/**
* Print a table to show all days of a specific month.
*
* Example: Farvardin, 1397
* printMonthMatrix(1397, 1)
*
* J P Ch Se D Y S
* --------------------------------------
* 3 2 1
* 10 9 8 7 6 5 4
@amrza
amrza / aria.sh
Created Apr 21, 2018
Download List of files with aria2
View aria.sh
#!/bin/sh
aria2c --dir=./ --input-file=urls.txt --max-concurrent-downloads=1 --connect-timeout=60 --max-connection-per-server=16 --split=16 --min-split-size=1M --human-readable=true --download-result=full --file-allocation=none
date
# Now create this file in the same directory and paste all urls in it: urls.txt
@amrza
amrza / run.py
Last active Jul 27, 2021
How to write RTL(Arabic/Persian) text on images in python.
View run.py
# Tested on Python 3.6.1
# install: pip install --upgrade arabic-reshaper
import arabic_reshaper
# install: pip install python-bidi
from bidi.algorithm import get_display
# install: pip install Pillow
from PIL import ImageFont
@amrza
amrza / reason.js
Last active Mar 23, 2018
reasonml
View reason.js
type schoolPerson = Teacher | Director;
let greeting = (stranger) =>
switch (stranger) {
| Teacher => "Hey professor!"
| Director => "Hello director."
};
Js.log(greeting(Teacher));
@amrza
amrza / private-access.java
Last active Feb 26, 2018
Objects of the same type will have access to each others private and protected members even though they are not the same instances! WTF!
View private-access.java
// Person.class
//-------------------------
class Person {
private String name;
public Person(String name) {
this.name = name;
}