Skip to content

Instantly share code, notes, and snippets.

View edib's full-sized avatar

ibrahim edib kokdemir edib

View GitHub Profile
@edib
edib / pywinrm.py
Created April 7, 2017 13:27
pywinrm usage
import winrm
ps_script = """wmic cpu get LoadPercentage"""
s = winrm.Session('<remote win ip>', auth=('localadmin', 'localadminpass'),transport="ntlm")
r = s.run_ps(ps_script)
#print r.status_code
print(r.std_out)
print("Error code: ",r.std_err)
@edib
edib / rename.py
Last active April 16, 2017 20:42
python bulk rename
import os
for afile in os.listdir('.'):
filename, file_extension = os.path.splitext(afile)
if not file_extension == '.xyz':
os.rename(afile, filename + '.tzy')
@edib
edib / wallpaper_copy.py
Last active April 28, 2017 14:23
copy windows 10's daily images form its secret dir to my wallpaper dir
import os, glob
from shutil import copyfile
from pathlib import Path
#my name
myLoginName = os.getlogin()
#my saving destination (whatever directory u want)
myImagesDir = "c:\\Users\\"+myLoginName+"\\Desktop\\wallpaper\\"
@edib
edib / json_to_csv.py
Created June 18, 2017 17:59
convert json output to csv file
import pandas as pd
# file or web page can be used
df=pd.read_json("http://url/json")
# print(df)
df.to_csv('results.csv')
@edib
edib / isPrimePrompt.py
Last active December 31, 2017 21:32
prompts for a number to check whether it is prime or not
def is_prime(x):
if x > 1:
n = x // 2
for i in range(2, n + 1):
if x % i == 0:
return False
return True
else:
return False
@edib
edib / readonlyuser.sh
Last active August 15, 2017 07:13
grant a read-only privilege to a role, takes db and role as parameters
# define role
role=$2
db=$1
echo "-- create user"
echo "CREATE ROLE $role ENCRYPTED PASSWORD '`mkpasswd 55`' LOGIN;"
echo "-- remove public access"
echo "REVOKE ALL ON SCHEMA public from $role;"
# get all schemes except public from specified database
@edib
edib / compress.sh
Last active February 6, 2022 11:14
postgres logs compress script
#!/bin/bash
echo "Job Started!" >> "log.compress.log" 2>&1
echo `date` >> "log.compress.log" 2>&1
find "/var/lib/pgsql/9.6/data/pg_log/" -type f -name "*.log" -mtime +1 | while read file ; do gzip -v $file >> "log.compress.log" 2>&1 ; done
echo `date` >> "log.compress.log" 2>&1
echo "Job Finished!" >> "log.compress.log" 2>&1
@edib
edib / rsyncwal.sh
Last active November 5, 2018 09:45
postgresql multiple host and pgbacrest wall archive script
#!/bin/bash
rsync -q -ae ssh $1 \ postgres@<replica1>:<xlog_archive_path>/$2
rsync -q -ae ssh $1 \ postgres@<replica2>:<xlog_archive_path>/$2
if [ $? != 0 ]
then
echo "Archiver error:"
exit 1
fi
@edib
edib / upgrade-postgres-9.4-to-9.6.md
Created September 11, 2017 08:21 — forked from dmitrykustov/upgrade-postgres-9.4-to-9.6.md
Upgrading PostgreSQL from 9.4 to 9.6 on Debian Jessie

To use the most modern version of Postgres software we need to add postgresql repository. Edit /etc/apt/sources.list or create /etc/apt/sources.list.d/pgdg.list and add there a line: deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main Then import the repository signing key, and update the package lists:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update

Install a new version of PostgreSQL server.

Once the Debian upgrade finished, I used dpkg-query -l postgresql* to check which versions of postgres I have installed.

@edib
edib / replace_with.sh
Last active September 14, 2017 17:35
loop list line by line and replace content another file and push it cumulative file
for replace_with_this in `cat list`
do
cp config config-temp
sed -i "s/replace_this/$replace_with_this/g" config-temp
cat config-temp >> config_all
done