Skip to content

Instantly share code, notes, and snippets.

View hasanisaeed's full-sized avatar
💥
I wake up early and work hard :)

Saeed hasanisaeed

💥
I wake up early and work hard :)
View GitHub Profile
@hasanisaeed
hasanisaeed / make_app.sh
Created June 29, 2021 12:40
Generate APK file without IDE
#!/bin/bash
#mkdir -p { src/com/example/hellovirgool, obj, bin, res/layout, res/values, res/drawable}
#Define the help function
function help() {
echo "Options:"
echo "-package Package Name"
echo "-sdk SDK Path"
echo "-name Application Name"
@hasanisaeed
hasanisaeed / fa2EnDigits.js
Last active July 12, 2021 12:30
Convert Persian digits to English digits.
fa2EnDigits(str) {
str = String(str);
var e = '۰'.charCodeAt(0);
str = str.replace(/[۰-۹]/g, function (t) {
return t.charCodeAt(0) - e;
});
e = '٠'.charCodeAt(0);
str = str.replace(/[٠-٩]/g, function (t) {
return t.charCodeAt(0) - e;
});
@hasanisaeed
hasanisaeed / GtoJ.js
Last active July 13, 2021 12:28
Convert Georgian to Shamsi(Jalali)
// https://www.linkedin.com/posts/ppx1400_ppx-progprox-afyahyabrafyahyabraepahyagpaeb-activity-6820335516840546304-eHMZ
function GtoJ(a){
var e,d,c;
var n,m,l;
var b,h;
var k;
var f;
var gdays=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
@hasanisaeed
hasanisaeed / restart_squence.sql
Last active March 20, 2024 08:55
Postgres: reset sequence from max(id) in all table.
CREATE OR REPLACE FUNCTION "reset_sequence" (tablename text, columnname text, sequence_name text)
RETURNS "pg_catalog"."void" AS
$body$
DECLARE
BEGIN
EXECUTE 'SELECT setval( ''' || sequence_name || ''', ' || '(SELECT MAX(' || columnname ||
') FROM ' || tablename || ')' || '+1)';
@hasanisaeed
hasanisaeed / split_csv_by_row.py
Last active October 7, 2021 04:31
Split .csv files by rows.
def split_and_save_df(df, name='NoName', chunk_size=100, output_dir=''):
"""Split a dataframe and save each chunk in a different csv file.
Parameters:
df : data frame ( df = pd.read_csv('file.csv')
name : name of output file
chunk_size : chunk size
output_dir : directory where to write the divided dataframe
"""
import os
@hasanisaeed
hasanisaeed / refactorFieldName.sql
Created September 22, 2021 07:33
Postgresql: Change field name in all table.
do
$$
declare
l_rec record;
begin
for l_rec in (select table_schema, table_name, column_name
from information_schema.columns
where table_schema = 'public'
and column_name = 'mount') loop
execute format ('alter table %I.%I rename column mount to amount', l_rec.table_schema, l_rec.table_name);
@hasanisaeed
hasanisaeed / icons.txt
Last active June 9, 2024 22:01
Git conventional commit icons.
🗑️ revert:
🐞 fix:
✨ feat:
💎 style:
♻️ chore:
📦 refactor:
🎉 build:
docs
-- Converting an int to a serial more or less only means adding a sequence default to the value, so to make it a serial;
-- Pick a starting value for the serial, greater than any existing value in the table
SELECT MAX(id)+1 FROM mytable
-- Create a sequence for the serial (tablename_columnname_seq is a good name)
CREATE SEQUENCE test_id_seq MINVALUE 3 (assuming you want to start at 3)
-- Alter the default of the column to use the sequence
ALTER TABLE test ALTER id SET DEFAULT nextval('test_id_seq')
@hasanisaeed
hasanisaeed / git.sh
Created October 14, 2021 12:13
Git in one line.
#!/bin/bash
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
WHITE='\033[0;m'
helpFunction() {
echo "***** USAGE *****"
echo "$0 -a add -m '<your message>'"
@hasanisaeed
hasanisaeed / mixins.py
Created January 25, 2022 04:25 — forked from ceolson01/mixins.py
Django Group Required Mixin
from django.core.exceptions import PermissionDenied
class GroupRequiredMixin(object):
"""
group_required - list of strings, required param
"""
group_required = None