Skip to content

Instantly share code, notes, and snippets.

View ilius's full-sized avatar

Saeed Rasooli ilius

  • Iran
  • 14:25 (UTC +03:30)
View GitHub Profile
#!/usr/bin/python
# -*- coding: utf-8 -*-
# recode a file from arabic windows(windows-1256) to utf8
import sys, os
def winArabicToUtf8(s, ar2fa=True):
u = s.decode('windows-1256')
if ar2fa:
for item in [
(u'ي',u'ی'),
(u'ك',u'ک'),
*.py[oc]
*~
#.Trash*
#.trash*
.hidden
*.patch*
*.bak
*.save
.hg
.bzr*
@ilius
ilius / jalali_ordinal.py
Created December 19, 2015 12:37
jalali_ordinal.py
'''
jd - ordinal = 1721425
jd = ordinal + 1721425
ordinal = jd - 1721425
>>> date=(2015, 12, 19) ; gregorian.to_jd(*date) - datetime(*date).toordinal()
1721425
'''
<?php
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$rsa->loadKey('<RSAKeyValue>
<Modulus>
...
</Modulus>
<Exponent>AQAB</Exponent>
<P>
import random
def weighted_choice(choices):
if isinstance(choices, dict):
choices = choices.items()
total = sum(w for c, w in choices)
r = random.uniform(0, total)
upto = 0
for c, w in choices:
if upto + w >= r:
#!/bin/bash
git show-ref --abbrev --heads | sed 's/refs\/heads\///g' | sort | uniq -w 7 -D
@ilius
ilius / sort_stream.py
Last active March 1, 2016 19:50
sort_stream.py
## https://gist.github.com/ilius/71cfdeb004b568ecd40c
from heapq import heappush, heappop
def hsortStream(stream, maxHeapSize, key=None):
"""
stream: a generator or iterable
maxHeapSize: int, maximum size of heap
key: a key function, as in `list.sort` method, or `sorted` function
#!/usr/bin/python
import os, sys
def getDateTime(imPath):## output sample: '2005:01:01_12:02:16'
if not os.path.exists(imPath):
print 'Error: Image file \''+imPath+'\' dose not exit!'
sys.exit(1)
if os.path.isdir(imPath):
print 'Error: \''+imPath+'\' is a directory!'
sys.exit(1)
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
#!/usr/bin/env perl
=dependencies:
sudo cpan get Mojolicious
sudo cpan get MongoDB
sudo cpan get Set::Light
sudo cpan get Log::Log4perl
sudo cpan get DateTime::Format::Strptime
sudo cpan get File::HomeDir
sudo cpan get Digest::SHA1