Skip to content

Instantly share code, notes, and snippets.

@swarminglogic
swarminglogic / autodirexec.py
Last active December 17, 2015 13:39
Monitors executables in a directory (passed as argument). Executables that are modified (based on md5sum) or introduced, are executed.
#!/usr/bin/env python
import sys, os, commands, time, errno
def getExecutablesAndMd5(directory):
"""
Returns a dictionary with the following.
Key: Paths to executable within specified directory.
Value: The md5sums of the executable.
"""
@swarminglogic
swarminglogic / autobuild.sh
Last active December 17, 2015 14:18
Watch over project files, and automatically rebuild project when files are modified. Created with SCons and C++ in mind, but can easily be customized.
#!/bin/bash
#
# Watch over project files, and automatically rebuild
# project when files are modified. Can easily be
# customized for different project types/languages.
#
# Use: ./autobuild.sh [executable]
#
# Optional: Pass path to executable to run whenever
@swarminglogic
swarminglogic / updatesdl.sh
Created May 27, 2013 14:08
Update and build latest SDL 2.0 -- automatic pull and update from repository, and compile SDL, SDL_image, SDL_mixer, SDL_net, SDL_ttf. Simple Direct,edia Library (http://www.libsdl.org/)
#!/bin/bash
prefixDir=`pwd`/sdl2-x86
# ------------------------------ Functions Start ------------------------------
function cloneSdlRepo {
(hg clone http://hg.libsdl.org/$1 && cd SDL && hg co default && hg pull -u)
}
function pullAndBuildSdlRepo {
@swarminglogic
swarminglogic / gifcapture.sh
Last active June 5, 2018 20:22
gifcapture -- A linux tool to record a region of the screen and convert it to a well optimized gif.
#!/bin/bash
delay=0.2
title='default'
count=0
loop=1 #0 for infinite loop
# Set if you want to skip mouse selection
if [[ $# -eq 6 ]]
then
@swarminglogic
swarminglogic / Main.cpp
Last active December 18, 2015 22:59
SFML-vs-SDL-benchmark, forked from github.com/eXpl0it3r/SFML-vs-SDL-Benchmark. Since it's just a silly and fairly nonconstructive benchmark, I prefer to not have it listed as a forked repository.
#include <iomanip>
#include <iostream>
int spritesSDL();
int spritesSFML();
int spritesAlphaSDL();
int spritesAlphaSFML();
@swarminglogic
swarminglogic / createwebfolder.sh
Last active December 19, 2015 02:59
Script to add and configure a virtual host to apache2 server. PS: Requires that /etc/apache2/ports.conf contains the lines "#ADD NAMEVIRTUALHOST" and "#ADD LISTEN" PPS: Rough script, but it gets the job done.
#!/bin/bash
#
# Modifies /etc/apache2/ports.conf to listen to specified port-number ($2)
# Adds configuration file to /etc/apache2/sites-available/$1.conf
# Creates symbolink to the above file in /etc/apache2/sites-enabled/$1.conf
# Restarts apache server.
#
# Note: This is a very rough script, and only used to automate a process.
# Not intended for production.
#
@swarminglogic
swarminglogic / focusscreen.sh
Created July 2, 2013 11:24
Script to move mouse cursor to the specified screen (for separate x screens).
#!/bin/bash
# Script to move mouse cursor to the specified screen (for separate x screens).
# Useful if set up to trigger with a global hotkey.
#
# e.g.: ./focusscreen.sh 0
#
if [ ! `which xdotool` ] ; then echo "You need xdotool!" && exit ; fi
@swarminglogic
swarminglogic / getoeis.sh
Created August 15, 2013 14:44
Bash script to crawl the OEIS database, and get the number of entries for each integer. See http://swarminglogic.com/articles/2013_08_oeis for more information.
#!/bin/bash
[[ ! "$1" == "-" && ! "$1" == "+" ]] && echo "Invalid sign paramter [-|+]" && exit;
[[ "$1" == "-" ]] && suff="neg";
[[ "$1" == "+" ]] && suff="pos";
cntfile='cntfile_'$suff
[[ ! -e $cntfile ]] && echo '0' > $cntfile;
file='values_'$suff
@swarminglogic
swarminglogic / nicekill.sh
Last active November 7, 2023 00:03
nicekill: A bash script to terminate a process in the order of SIGTERM, SIGINT, SIGHUP, SIGKILL, giving each signal 2 seconds to enact.
#!/bin/bash
# $1: PID
# Returns true if a process exists with pid=PID
function isProcessAlive {
if [ `ps -p $1 | wc -l` -gt 1 ] ; then
return 0;
else
return 1;
fi
@swarminglogic
swarminglogic / recordscreen.sh
Last active November 25, 2022 06:45
recordscreen: A bash script for timelapse recordinging two separate X displays, and creating a picture-in-picture overlay with one display
#!/bin/bash
if [ ! $# -eq 2 ] ; then
echo "Usage: ./recordscreen delay outputfolder"
exit
fi
if [ ! -d $outputFolder ] ; then
echo "Output folder does not exist"
exit