Skip to content

Instantly share code, notes, and snippets.

@alenbasic
alenbasic / timestables.py
Created June 17, 2016 12:48
A simple timestables generator. Saw an exercise online and thought I'd give it a go. One improvement you could make is to convert the stored values to strings so you could pad smaller values up so everything nicely aligns.
def timestables(size):
table = [[0 for i in range(size)] for i in range(size)]
for j in range(size):
for i in range(size):
table[j][i] = (i+1)*(j+1)
table[i][j] = (i+1)*(j+1)
for line in table:
print line
timestables(15)
@alenbasic
alenbasic / bashingimgur.sh
Last active May 26, 2017 09:47
A simple hackish script that uploads pictures to imgur. Improve and expand from here.
screenshot="$1"
client_id="" # get your clientid here: https://api.imgur.com/oauth2/addclient
response=$(curl -silent -H "Authorization: Client-ID $client_id" -F "image=@${screenshot}" https://api.imgur.com/3/image.json)
url=$(echo $response | awk '{split($0,a,","); print a[48]}' | sed 's/\(\\\|"link":\|}\|"\)//g')
deletehash=$(echo $response | awk '{split($0,a,","); print a[46]}' | sed 's/\("deletehash":\|"\)//g')
echo "$url" | xclip -selection c # needs xclip installed, available most linux distros
echo "$url"
echo "deletion page: http://imgur.com/api/delete/${deletehash}"
@alenbasic
alenbasic / aurhelper.sh
Last active October 19, 2015 22:16
A simple AUR helper script. It moves and extracts a snapshot downloaded from the AUR to a build directory, allows you to compile it and when done moves the binary package to a bin folder and deletes the downloaded files
#!/bin/bash
# run this by sourcing it, i.e. "source aur -x" or ". aur -r"
# you can make it easier on yourself by making a alias
# for example, alias aurhelper="source /path/to/aurhelper.sh"
src_dir="/home/user/aur_packages/src/" # change these to whatever you'd like
bin_dir="/home/user/aur_packages/bin"
case "$1" in
@alenbasic
alenbasic / pacwrapper.sh
Last active October 19, 2015 22:08
A simple pacman wrapper script that allows you to search for packages in pacman and then if you'd like, install them.
#!/bin/bash
# The output is similar to what you'd see by simply running pacman -Ss "search term"
# but each package name is prepended with a number. If you wish to install any of the
# packages after making a search, you simply enter in the number of the package, otherwise
# q to quit. Once you select which package to install, pacman -S is run and will ask for your
# password and confirm if you really wish to install the package.
search_term="$1"
@alenbasic
alenbasic / iso2usb.sh
Last active October 3, 2015 00:13
A simple script for OSX for taking ISOs and imaging them onto USBs.
#!/bin/bash
# iso2usb is a simple script for OSX to ease the conversion of an iso to an img file
# and then dd that img file to a USB of your choosing. You simply give it the iso
# as a parameter and then the disk number and it will take care of the rest.
# based on the commands here: http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-mac-osx
# and the color commands here: http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
# exits out of the script upon error
@alenbasic
alenbasic / lfs.sh
Last active October 4, 2016 11:01
A simple script I used to help automate some tasks while doing Linux From Scratch
#!/bin/bash
# run this by sourcing it, i.e. "source lfs -t" or ". lfs -t"
# you can make it easier on yourself by making an alias
# for example, alias lfs="source /path/to/lfs.sh"
# colors to use within the script
BLACK='\033[0;30m'
DGRAY='\033[1;30m'
@alenbasic
alenbasic / lowbattery.sh
Last active August 29, 2015 14:04
Was assigned to a cron job and if the power was low would send a notification saying so.
# this was initially designed for cinnamon, but cinnamon in its latest update offers this "out of the box"
export DISPLAY=:0.0
charge=$(cat /sys/class/power_supply/BAT1/capacity)
status=$(cat /sys/class/power_supply/BAT1/status)
if [[ $status != "Charging" ]]; then
if [[ $charge < 20 ]]; then
notify-send "Charge now is at $charge%" "Plug it in now!" --icon=dialog-warning
elif [[ $charge < 10 ]]; then
@alenbasic
alenbasic / weather.py
Created July 26, 2014 15:42
A simple script when run pops up with a libnotify notification. Assigned to a keyboard shortcut and works like a charm!
# -*- coding: utf-8 -*-
#!/user/bin/python
from gi.repository import Notify; import json; import urllib2; import sys
reload(sys); sys.setdefaultencoding("utf-8")
city_name = "Insert City Name Here"
city_data = json.load(urllib2.urlopen("http://api.openweathermap.org/data/2.5/weather?q="+city_name))
city_temp = str(city_data['main']['temp']-273.15)
city_weather = city_data['weather'][0]['description']
@alenbasic
alenbasic / .Xmodmap
Last active October 19, 2015 22:20
~/.Xmodmap - Remapped keys to work properly on my Toshiba C50-B032
# NOTE: As of the Linux kernel version 4.2.3,
# the keyboard works out of the box and this is no longer required
keycode 8 =
keycode 9 = Escape NoSymbol Escape
keycode 10 = 1 exclam 1 exclam
keycode 11 = 2 at 2 at
keycode 12 = 3 numbersign 3 numbersign
keycode 13 = 4 dollar 4 dollar
keycode 14 = 5 percent 5 percent
keycode 15 = 6 asciicircum 6 asciicircum
import dropbox
import time
import os
APP_KEY = ''
APP_SECRET = ''
ACCESS_TOKEN = ""
TIMESTAMP = time.strftime('%Y-%m-%d')
FILENAME = "filename.sql"