Skip to content

Instantly share code, notes, and snippets.

View bharadwaj-raju's full-sized avatar

Bharadwaj Raju bharadwaj-raju

  • New Delhi, India
View GitHub Profile
bharadwaj-raju /
Last active January 6, 2018 10:35
Simple "database" class in Python -- basically a dict which can load-from/write-to disk without you manually calling json.load()/json.dump()
import json
class DataBase(object):
def __init__(self, path):
self.path = path
bharadwaj-raju /
Created December 23, 2017 16:13
bharadwaj-raju /
Created October 23, 2017 16:13
Simple AES enc/dec python
import struct
from Crypto.Cipher import AES
def pad16(s):
t = struct.pack('>I', len(s)) + s.encode('utf-8')
return t + b'\x00' * ((16 - len(t) % 16) % 16)
def unpad16(s):
n = struct.unpack('>I', s[:4])[0]
return s[4:n + 4]

IHDRA���R pHYs���+ IDATx��w\����5�NzPAA���cK�
;�Xbb/��5�(h�]�'E��p�;�ë;�?��w'��|?��ev�M�7�f���~����@��� ���߈
��`�*4G>�o�}� ���:��J#��t�4&B� ���c���Mӂ�`0j|�a𓏯$�;#��
���`L���+!u���?���[<�b0�W�n�������W_A c,H��~�1���*����s�V&��|����?&I��
Y���k`r�����]��0%[C%bZX1�!J�V!+�f󕢩�_��c���b!�E���C�L_�Q!HߣϽ-ŰEE!�J_��}��C�Q`��7�aU����`̂��ù����gϞ;{�zH�����������C�JB���f�]ZiS5�1x�MC�Me�=�d� ������N�А=�_�~��gm�Hhj�JU]�:�t?����V�!ݻ���,J�;�������?���C� �=`�B29�
&�PJxo�Ed�������+AT�y�gΈ>엪-�񸸸\J��`0��s�� ��b���ǦUhȜٳ��ܘLf߾��Ǐ#I��1�nQ/� L�_߆G��R|c�b����E�V�!�g�rwsc0�}�Qu]�L�zA����}��7����n��2+�R� ��I/7š(x�B\&�H%e�{w>=�SB��U���?7o��/;++��
bharadwaj-raju /
Created March 16, 2017 05:12
Python program loop
import sys
while True:
# code here
print('Do you want to start the program again? (Y/N)')
response = input('> ').strip().upper()
if response == 'Y':
bharadwaj-raju /
Last active September 8, 2023 12:31
simple python fileserver with authentication

Credit to bones7456.


Change values in, place it in the same directory as then run python2

#!/usr/bin/env python3
import sys
import os
def parse_xdg_desktop(desktop_file_or_string):
'''Parse a .desktop file.
Parse an XDG .desktop file or a string with its contents into an easy-to-use dict, with standard values present even if not defined in file.
# Show list of todos before commit
find -name $SOURCE_CODE_GLOB -exec grep TODO {} /dev/null \; | sed -e 's/\t//g;s/.py:/.py: \t/g;s/.py:.*#/\t/g'
! "Enabled modi" Set from: Default
! rofi.modi: window,run,ssh
! "Window opacity" Set from: Default
! rofi.opacity: 100
! "Window width" Set from: Default
! rofi.width: 50
! "Number of lines" Set from: Default
! rofi.lines: 15
! "Number of columns" Set from: Default
! rofi.columns: 1