Skip to content

Instantly share code, notes, and snippets.

@sanchitgangwar
sanchitgangwar / is_completion.sh
Created January 29, 2013 13:46
Inline file search - bash completion
_is()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ ${cur} == * ]]; then
COMPREPLY=( $(find ./ -maxdepth 1 -iname "*${cur}*" | cut -d '/' -f 2) )
return 0
@sanchitgangwar
sanchitgangwar / is_script.sh
Last active December 11, 2015 21:39
Inline file search script
#! /bin/bash
filename="$1"
echo -n "Enter the command name: "
commandName=""
while [ -z "$commandName" ];
do
read commandName
done
@sanchitgangwar
sanchitgangwar / batteryBrightness.sh
Created September 7, 2012 16:54
Auto adjust brightness with remaining battery
#! /bin/bash
while true
do
chargingState=$(grep "charging state:" /proc/acpi/battery/BAT0/state | awk '{print $3}')
batteryFull=$(grep "design capacity:" /proc/acpi/battery/BAT0/info | awk '{print $3}')
batteryRemaining=$(grep "remaining capacity:" /proc/acpi/battery/BAT0/state | awk '{print $3}')
batteryPercentage=$((batteryRemaining * 100/batteryFull))
@sanchitgangwar
sanchitgangwar / moveFiles.py
Created July 4, 2012 19:40
Move files from multiple directories to one.
#! /usr/local/bin/python3.2
# Moves files from multiple directories to one, and renames them if necessary.
# WHEN IS THIS SCRIPT USEFUL:
# If you have files in multiple directories, say ABC, ABC-1, ABC-2,
# then all the files from the directores will be moved to directory ABC
# and the other directories would be removed.
# If a file with that name already exists, it will be renamed and then moved.
# Renaming: <filename> ==> ABC--<filename>--<some_number>
@sanchitgangwar
sanchitgangwar / robot_simple.py
Created March 29, 2012 06:54
Bomb Defusing Tobot
#! /usr/bin/python
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
import random
from random import randrange, randint
def printRobot(win, pos_x, pos_y, size):
''' Prints the Robot '''
for i in range(size):
@sanchitgangwar
sanchitgangwar / robot_advanced.py
Created March 29, 2012 06:52
Bomb Defusing Robot Advanced
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
import random
from random import randrange, randint
class Box:
pass
def Game(pos_x, pos_y, size):
@sanchitgangwar
sanchitgangwar / snake.py
Created March 22, 2012 12:38
Snakes Game using Python
# SNAKES GAME
# Use ARROW KEYS to play, SPACE BAR for pausing/resuming and Esc Key for exiting
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint
curses.initscr()
win = curses.newwin(20, 60, 0, 0)
@sanchitgangwar
sanchitgangwar / snake.py
Created March 22, 2012 12:37
Snakes Game using Python
# SNAKES GAME
# Use ARROW KEYS to play, SPACE BAR for pausing/resuming and Esc Key for exiting
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint
curses.initscr()
win = curses.newwin(20, 60, 0, 0)