Skip to content

Instantly share code, notes, and snippets.

View ilius's full-sized avatar

Saeed Rasooli ilius

  • Iran
  • 04:21 (UTC +03:30)
View GitHub Profile
@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
@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
#!/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)
import random
from math import log
'''
findMaxDisplace = lambda array: \
max(
origIndex - sortedIndex \
for sortedIndex, (origIndex, value) in \
enumerate(
sorted(
#!/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
@ilius
ilius / jalali-plpgsql.sql
Last active January 18, 2024 14:06
Jalali Date Conversion in PL/pgSQL
create or replace function epoch_to_jd(float) RETURNS int as $$
BEGIN
return ($1 / (24*3600) + 2440588)::int;
END;
$$ LANGUAGE plpgsql;
create or replace function timestamp_to_jd(timestamp with time zone) RETURNS int as $$
BEGIN
return epoch_to_jd(extract (epoch from $1));
@ilius
ilius / job-ad-guide.md
Last active March 7, 2024 06:15 — forked from hristian-carabulea/Guide.md
A Guide to Software Developer Job Advertisements
Job Description Actual meaning
A fast-paced environment Your job will be constant firefighting
A market leader Recently started making a profit
Able to work with minimal spervision You'll be the one we blame when something goes wrong
An Agile team We have daily stand-ups
Dynamic environment Our leadership keeps changing priorities
Must be a team player Must not question authority
Ninja You do all the work alone
Passionate You wil