Skip to content

Instantly share code, notes, and snippets.

@alenbasic
alenbasic / mhp.py
Created April 19, 2014 08:26
The Monty Hall Problem
import random
right = 0.0
wrong = 0.0
x = 100000
for i in range(x):
items = ['goat','prize', 'goat']
random.shuffle(items)
choice = random.randrange(0,3)
choice_name = items[choice]
import dropbox
import time
import os
APP_KEY = ''
APP_SECRET = ''
ACCESS_TOKEN = ""
TIMESTAMP = time.strftime('%Y-%m-%d')
FILENAME = "filename.sql"
@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 / 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 / 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 / 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 / .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
@alenbasic
alenbasic / palin_list.py
Created February 9, 2013 00:57
List of palindromes based on the words file in *nix systems.
a = []
b = []
i = 0
z = 0
for line in open('/usr/share/dict/words', 'r').readlines():
while i < len(line)-2:
a.append(line[i])
i = i + 1
while i > 0:
b.append(line[i])
@alenbasic
alenbasic / arab_roman.py
Created February 9, 2013 01:01
Arabic/Roman numerals converter
i = 0
count = 0
str = ''
roman_list = [1000,900,500,400,100,90,50,40,10,9,5,4,1]
roman_dict = {1000:'M',900:'CM',500:'D',400:'CD',100:'C',90:'XC',50:'L',40:'XL',10:'X',9:'IX',5:'V',4:'IV',1:'I'}
arabic_dict = {'M':1000, 'CM':900, 'D':500, 'CD':400, 'C':100, 'XC':90, 'L':50, 'XL':40, 'X':10, 'IX':9, 'V':5, 'IV':4, 'I':1}
while True:
print '1. Arabic to Roman'
print '2. Roman to Arabic'