Skip to content

Instantly share code, notes, and snippets.

View mrunderline's full-sized avatar
🐢

Ali Madihi mrunderline

🐢
View GitHub Profile
@mrunderline
mrunderline / jalali-plpgsql.sql
Created September 25, 2023 10:07 — forked from ilius/jalali-plpgsql.sql
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));
END;
@mrunderline
mrunderline / app.js
Last active August 5, 2022 21:07
simple node js cluster with mysql connections
const express = require('express');
const cluster = require('cluster');
const mysql = require('mysql');
const numCPUs = require('os').cpus().length;
const app = express();
const PORT = 3000;
const pool = mysql.createPool({
@mrunderline
mrunderline / retry.py
Created May 25, 2022 08:34
this is a decorator that help you to retry on specific exceptions dynamically
import time
def retry(exceptions, max_tries=5, delay=1):
def decorator(function):
def wrapper(*args, **kwargs):
attempt = 0
while attempt < max_tries:
try:
return function(*args, **kwargs)
#!/bin/bash
website="$1"
certificate_file=$(mktemp)
echo -n | openssl s_client -servername "$website" -connect "$website":443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $certificate_file
date=$(openssl x509 -in $certificate_file -enddate -noout | sed "s/.*=\(.*\)/\1/")
date_s=$(date -d "${date}" +%s)
now_s=$(date -d now +%s)
date_diff=$(( (date_s - now_s) / 86400 ))
echo "$website will expire in $date_diff days"
@mrunderline
mrunderline / convert-raw-pdf-to-picture-pdf.sh
Created September 30, 2020 08:48
this script will compress pdf, convert to picture, compress again and check the size. so you can use this script if your pdf file contain some secretly content to prevent other to stole it!
source_path='/path/to/booklet'
target_path='/path/to/result'
dpi=200
quality=25
max_size=1536 # in kb
pdf2pic() {
dirname="${i%.*}"
mkdir -p "$dirname"
-- 1. Select items by the value of a first level attribute (#1 way)
SELECT * FROM users WHERE metadata @> '{"country": "Peru"}';
-- 2. Select items by the value of a first level attribute (#2 way)
SELECT * FROM users WHERE metadata->>'country' = 'Peru';
-- 3. 3. Select item attribute value
SELECT metadata->>'country' FROM users;
-- 4. Select only items where a particular attribute is present
@mrunderline
mrunderline / g2j.sql
Last active October 4, 2024 09:39
a postgres function that convert Gregorian date to Jalali
CREATE OR REPLACE FUNCTION g2j(in_date timestamp with time zone)
RETURNS character varying AS
$BODY$
DECLARE
aday smallint;
amonth smallint;
ayear smallint;
a1 char(4);
b1 char(2);
c1 char(2);
@mrunderline
mrunderline / digikala_word_finder.py
Created February 8, 2019 19:03
This code help you to find your product in digikala.com which has a specific word in params!
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
url = 'https://www.digikala.com/search/category-tablet/?has_selling_stock=1&type[0]=211&attribute[A20378][0]=25460&attribute[A20378][1]=25462&attribute[A20421][0]=25676&attribute[A20421][1]=25677&pageno=1&last_filter=type&last_value=211&sortby=4'
word = 'قلم'
first_char = '?'
if first_char in url:
@mrunderline
mrunderline / lottery code
Last active May 11, 2021 06:34
a short code for selecting (sth) randomly from a list in java!
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.Collections;
import java.util.Scanner;
public class randomEmail {
public static void main(String[] args) {
import java.util.Scanner;
public class madihi {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("enter n = ");
int n = scan.nextInt();
int[] a = new int[n+1];
int sum1 = 0;
for(int i = 1 ; i < n ; i++){
System.out.print("enter number " + i + " = ");