Skip to content

Instantly share code, notes, and snippets.

@iambibhas
iambibhas / is_prime.py
Last active December 21, 2015 04:49
Checks if the given number is prime
import sys
import math
def is_prime(number):
if number <= 1:
return False
if number == 2:
return True
@iambibhas
iambibhas / crontab.sh
Created September 12, 2013 05:42
Poor man's time management
50 * * * * export DISPLAY=:0.0 && export XAUTHORITY=/home/bibhas/.Xauthority && /usr/bin/notify-send "Take a break!"
@iambibhas
iambibhas / README.md
Last active August 10, 2020 10:09
Python script to upload image to imgur from linux terminal. Must have the `sh` package installed.

This uses sh package. Install it using pip.

$ (sudo )pip install sh

Then place this script with the name imgur in some location that's in your PATH, chmod +x the file and upload like this

$ imgur ~/Pictures/Screenshot\ from\ 2013-10-06\ 20:01:32.png

@iambibhas
iambibhas / 70-persistent-cd.rules
Last active December 25, 2015 17:39
Udev rule to add for Xfburn to detect Buffalo external DVD drive as writer
# Add this line to /etc/udev/rules.d/70-persistent-cd.rules
ENV{ID_SERIAL}=="BUFFALO_Optical_Drive_xxxxxxx", ENV{ID_TYPE}="cd", ENV{GENERATED}="1"
# Replace xxxxxxx with your drive's serial number. You can find it in /proc/scsi/usb-storage/
# It should be in one of the files (named with numbers denoting each USB devices attached)
# The content should be like this -
#
# Host scsi8: usb-storage
# Vendor: BUFFALO
@iambibhas
iambibhas / rpostgresql.R
Created November 6, 2013 17:11
Just the basic commands to connect to a PostgreSQL database from R and read a table or a query.
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="test", host="localhost", user="test", password="")
rs <- dbSendQuery(con, "select * from schools_school")
dframe <-dbReadTable(con,"schools_school").
@iambibhas
iambibhas / history.log
Created November 18, 2013 17:24
Postgres configuration after installing from the relinux image
sudo useradd postgres
sudo chown -R postgres:postgres /usr/lib/postgresql/
sudo chown -R postgres:postgres /var/lib/postgresql/
sudo chown -R postgres:postgres /var/log/postgresql/
sudo chown -R postgres:postgres /etc/postgresql/
sudo cd /var/lib/postgresql/9.1/main/
sudo mv server.key server.key-0
sudo cp /etc/ssl/private/ssl-cert-snakeoil.key server.key
sudo chown postgres server.key
sudo chgrp postgres server.key
@iambibhas
iambibhas / date_in_filename.md
Created November 18, 2013 18:40
Having datetime in file name with shell script

Date time for file name -

$ date +"%b-%d-%y"
Nov-19-13
$ touch `date +"%b-%d-%y"`.txt # works

Full list -

%a : Abbreviated weekday name (Sun..Sat)

%b : Abbreviated month name (Jan..Dec)

@iambibhas
iambibhas / samba-conf.sh
Created November 24, 2013 15:26
To Enable samba sharing on Ubuntu, must create samba password for the login user
sudo smbpasswd -a username
# https://help.ubuntu.com/community/Samba/SambaServerGuide
@iambibhas
iambibhas / backup.zsh
Last active December 29, 2015 08:48
Backup script to run on cron or on demand
# Destination directory where backups should be put
DEST_DIR="/media/bibhas/My Passport/Backup"
# List of directories to backup
# each directory in a new line
DIRS="/mnt/Works/
/etc/
/home/bibhas/
"
@iambibhas
iambibhas / backupdb.sh
Last active December 30, 2015 11:09
Postgresql database backup script
# IMPORTANT: Run this from the machine that's running the DB
# e.g. Vagrant box. Or change the HOST variable
# Destination directory where backups should be put
DEST_DIR="."
HOST="localhost"
DBUSER="user"
# List of directories to backup
# each directory in a new line