Skip to content

Instantly share code, notes, and snippets.

View RecNes's full-sized avatar
🎯
Focusing

Sencer H. RecNes

🎯
Focusing
View GitHub Profile
@RecNes
RecNes / README.md
Created August 27, 2021 08:18 — forked from hofmannsven/README.md
Git Cheatsheet
@RecNes
RecNes / sort_query_set_objects.py
Last active July 24, 2020 14:33
Sort object list in python
def sort_query_set_objects(query_set, attr=None):
"""
Convert queryset to a list array and sort by field with order ASC/DESC.
Use when you have to apply ordering to queryset but don't want to do it via database.
:param query_set: queryset
:param attr: query object attribute (field) name with order direction. Usage is same as order_by()
:return: list array w/wo sorted
"""
object_list = list(query_set)
@RecNes
RecNes / kill_the_snake.sh
Last active July 24, 2020 14:30
Shell script to use for kill all python scripts.
#!/usr/bin/env bash
# title : kill_pyhton.sh
# description : This script to use for kill python scripts.
# author : Sencer HAMARAT "sencerhamarat(at)gmail.com"
# date : 20160202
# version : 0.1
# command : bash kill_pyhton.sh
# bash_version : 4.3.11(1)-release
# =============================================================================
ARGS="$@"
import os
import time
def get_console_width():
"""
Returns the width of console.
NOTE: The below implementation works only on Linux-based operating systems.
If you wish to use it on another OS, please make sure to modify it appropriately.
"""
@RecNes
RecNes / 16x2lcdPrint.ino
Created November 18, 2016 17:25
Arduino gist for proper usage of vertical scrolling on each output with 16x2 LCD display.
#include <LiquidCrystal.h>
String Line1;
String Line2;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void lcdPrint(String lcdText) {
lcd.clear();
Line1 = Line2;
lcd.setCursor(0, 0);
lcd.print(Line1);
@RecNes
RecNes / ram_usage.sh
Last active June 20, 2018 08:40
This script will displays or sends email for RAM usage statistics of python scripts
#!/usr/bin/env sh
#title : ram_usage.sh
#description : Shell script for displaying RAM and Thread statistics of python scripts.
#author : Sencer HAMARAT "sencerhamarat(at)gmail.com"
#date : 20161014
#version : 0.4
#usage : sh ram_usage.sh
#==============================================================================
#!/usr/bin/env bash
SERVERNAME=$(hostname -f)
@RecNes
RecNes / cli_percentage.py
Last active June 20, 2018 08:37
Display percentage of process to on one line of stdout in python
object_list_length = len(ObjectList)
for i, object in enumerate(ObjectList):
percentage = int(((i + 1) * 100 / object_list_length))
percent_str = ""
for k in range(0, int(percentage / 5)):
percent_str += ":"
sys.stdout.write("\r%s -- %s | %s %% %s " % (str(i + 1),
str(object_list_length),
str(percentage),
@RecNes
RecNes / remove_old_hourly_backups.py
Last active June 20, 2018 08:35
Remove old hourly backups
#!/usr/bin/env python
import shutil
import os
from datetime import datetime
print(" ".join(("-"*20, "Removing Hourly Backups Older Than Today", "-"*20)))
path_to_backups = '/var/backups/sqlbackups'
today = datetime.today().date()
@RecNes
RecNes / repeatedly_mount.py
Last active June 20, 2018 08:33
Script for automatic file system check and mount usb disk for raspberry pi raspbian
"""
Please READ carefuly first and use at your OWN RISK!
This script is repeatedly try to mount EXT4 partition to given point.
Any other FS types are igored while writing this script. Works ONLY EXT4!
Before mounting, checks and corrects the file system errors. THIS MAY CAUSE LOSS OF DATA!
Append cronjob such as:
15 * * * * /usr/bin/python /root/repeatedly_mount.py
@RecNes
RecNes / disk_usage_mail_alert.py
Last active June 20, 2018 08:32
Disk space usage email alert
#!/usr/bin/env python
"""
Developen on: Python 2.7.13
"""
__author__ = 'Sencer Hamarat'
__license__ = "Creative Commons Attribution-ShareAlike 3.0 Unported License"
__version__ = "1.3"
__maintainer__ = "Sencer Hamarat"
__status__ = "Production"