Skip to content

Instantly share code, notes, and snippets.

View ilius's full-sized avatar

Saeed Rasooli ilius

  • Iran
  • 04:42 (UTC +03:30)
View GitHub Profile
@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));
#!/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
import random
from math import log
'''
findMaxDisplace = lambda array: \
max(
origIndex - sortedIndex \
for sortedIndex, (origIndex, value) in \
enumerate(
sorted(
#!/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)
#!/bin/bash
git show-ref --abbrev --heads | sed 's/refs\/heads\///g' | sort | uniq -w 7 -D
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:
<?php
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$rsa->loadKey('<RSAKeyValue>
<Modulus>
...
</Modulus>
<Exponent>AQAB</Exponent>
<P>
@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
'''
@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 / psql_mem_tuner.py
Last active March 7, 2024 06:20
PostgreSQL Memory Tuner
total_memory_percentage = 20.0
total_memory_max_megabytes = 8000
memory_params_percentage = {
'shared_buffers': 25.0,
'work_mem': 1.0,
'maintenance_work_mem': 12.0,
'effective_cache_size': 62.0,
}