Skip to content

Instantly share code, notes, and snippets.

@amrza
amrza / infix.kt
Created November 2, 2018 16:14
fun with infix funs in kotlin
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 June 22, 2018 20:20
Convert numbers to FA/EN [alternative]
/**
* 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 July 27, 2022 13:33
Convert numbers to FA/EN
/**
* 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': '۹'
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 " ";
}
/**
* 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 April 21, 2018 15:50
Download List of files with aria2
#!/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 September 13, 2024 01:30
How to write RTL(Arabic/Persian) text on images in python.
# 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 March 23, 2018 12:13
reasonml
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 February 26, 2018 05:55
Objects of the same type will have access to each others private and protected members even though they are not the same instances! WTF!
// Person.class
//-------------------------
class Person {
private String name;
public Person(String name) {
this.name = name;
}