Skip to content

Instantly share code, notes, and snippets.

@theSage21
theSage21 / .bashrc
Last active October 8, 2015 08:43
ratpoison low battery alert
function ratbatalert ()
{
# low battery alert for ratpoison
while true;
do
batt=$(upower -e|grep BAT0)
string_percent=$(upower -i $batt|grep 'percent')
percent=$(sed "s,percentage: ,," <<< $string_percent)
number=${percent::-1}
state=$(upower -i $batt|grep 'state')
@theSage21
theSage21 / .bashrc
Created October 15, 2015 06:11
My bashrc
alias l="ls"
alias ll="ls -l"
alias la="ls -a"
alias act="source env/bin/activate"
alias v="vim"
alias v3="virtualenv -p python3 env"
alias v2="virutalenv -p python2 env"
Blue='\[\e[01;34m\]'
White='\[\e[01;37m\]'
@theSage21
theSage21 / new_judge.sh
Created November 7, 2015 15:58
Add a new openjudge interface with questions in a folder called questions.
#! /bin/bash
git clone --depth 1 https://github.com/theSage21/judge-interface
cp -r questions judge-interface/webserver/
cd judge-interface
./setup.sh
source env/bin/activate
cd webserver
cp -r questions/* ./
python upload.py
@theSage21
theSage21 / bookreader.py
Created February 21, 2016 12:33
Simple book reader for reading text files using espeak
import os
import sys
import time
import configparser
from threading import Thread
ALIVE = True # SOFTWARE IS RUNNING
SPEAKING = True # IS It speaking
book = sys.argv[1]
# We use a class since, well it makes more sense this way and
# is easier to maintain in the future
class DB:
'''
BelonQuery Database
'''
def __init__(self, columns_and_types):
'''
columns must be list of (colname, type)
@theSage21
theSage21 / regex-engine.py
Created May 14, 2016 07:24
A very simple regular expression engine for learning purposes
# Define some special things
SPECIAL = '*|'
ALPHABET = '10'
EPSILON = None
# functions
def automaton_print(automaton):
"Neatly prints the automaton"
states, alphabet, start, final, transfer = automaton
print('STATES : ', states)
@theSage21
theSage21 / rot_forest.py
Created July 23, 2016 03:54
Random Rotation Forest implementation
# Based on
# https://www.packtpub.com/books/content/rotation-forest-classifier-ensemble-based-feature-extraction
from sklearn.datasets import make_classification
from sklearn.metrics import classification_report
from sklearn.cross_validation import train_test_split
from sklearn.decomposition import PCA
from sklearn.tree import DecisionTreeClassifier
import numpy as np
def get_data():
@theSage21
theSage21 / get_back.py
Created July 31, 2016 07:37
Warns you when you get too close to the screen
import os
import time
import cv2
import sys
print('python script.py harr.xml 1')
print(sys.argv)
script, casc, nodisplay = sys.argv
nodisplay = (nodisplay == '0')
@theSage21
theSage21 / perceptron.py
Created August 11, 2016 17:34
Simple perceptron code.
# AUTHOR: Arjoonn Sharma
# LICENSE: MIT
# Recommended Reading before tinkering with code:
# https://en.wikipedia.org/wiki/Heaviside_step_function
# https://en.wikipedia.org/wiki/Perceptron
def dot_product(vector1, vector2):
"Returns the dot product between two vectors"
# assertions allow us to make sure some things are true before
# we proceede. Here dot product is only defined for vectors
@theSage21
theSage21 / C_codechef_viz.py
Created December 9, 2016 01:55
Visualizing C programs from the Codechef database.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
import pickle
from collections import deque
import multiprocessing as mp
import editdistance
import os