Skip to content

Instantly share code, notes, and snippets.

View filviu's full-sized avatar

Silviu Vulcan filviu

View GitHub Profile
@filviu
filviu / imgur-down.py
Last active May 20, 2016 08:26
Download from imgur using api and saving descriptions together with pictures. Downloads in current folder. You need to register for a client id and secret
#!/usr/bin/python
import textwrap
from urllib import urlretrieve
from progressbar import ProgressBar, Percentage, Bar
from imgurpython import ImgurClient
@filviu
filviu / confparser.sh
Last active December 7, 2015 12:58
BASH config parser; reads three value pairs from .cfg file (I use it to store the target file as well so I can modifiy multiple configuration files) ignores whitespace and comments.
#!/bin/bash
set -o nounset # Treat unset variables as an error
shopt -s extglob
configfile="file.properties"
WEB_VARIABLE_FROM_PARRENT="www.example.com"
tr -d '\r' < $configfile | while IFS='= ' read TARGETFILE VARNAME VARVALUE
do
# Don't declare variables here, you are in a sub-shell that dies
@filviu
filviu / bg-launch.sh
Created December 7, 2015 12:41
Launch multiple processes in the background with separate log files and random delay
# seq: no of processes
# RANDOM %3 max. delay of 2s
for i in $(seq 10); do ./bin/cmd --param1 --param2 > output_$i.txt 2>&1 & sleep $(($RANDOM %3));done
@filviu
filviu / ansible-playbook.bat
Last active December 7, 2015 09:55
Ansible wrappers to run widows vagrant from cygwin ansible. The .bat needs to be in the windows PATH and the .sh is needed to change the path vagrant passes to ansible to *nix style path.
@echo off
set CYGWIN=C:\usr\cygwin64
set SH=%CYGWIN%\bin\bash.exe
"%SH%" -c "/usr/local/bin/ansible-winpath-playbook.sh %*"
@filviu
filviu / example.com.conf
Created December 2, 2015 10:33
Hotlink protection
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} /images/documents [OR]
RewriteCond %{REQUEST_URI} /images/stories [OR]
RewriteCond %{REQUEST_URI} /media/kunena/attachments/
RewriteCond %{HTTP_REFERER} !qgcio.qld.gov.au/.*$ [NC]
RewriteCond %{REMOTE_ADDR} !^172\.19\.2\.3$
RewriteCond %{REMOTE_ADDR} !^119\.9\.16\.90$
RewriteCond %{REQUEST_URI} !\.(jpg|png|gif)$ [NC]
RewriteRule .* https://www.example.com/
@filviu
filviu / 30detectproxy
Created December 2, 2015 10:26
apt-get use a proxy only if available. Shamelessly lifted from here: http://askubuntu.com/questions/53443/how-do-i-ignore-a-proxy-if-not-available
# /etc/apt/apt.conf.d/30detectproxy:
# Fail immediately if a file could not be retrieved. Comment if you have a bad
# Internet connection
Acquire::Retries 0;
# undocumented feature which was found in the source. It should be an absolute
# path to the program, no arguments are allowed. stdout contains the proxy
# server, stderr is shown (in stderr) but ignored by APT
Acquire::http::ProxyAutoDetect "/etc/apt/detect-http-proxy";
@filviu
filviu / Controly.md
Created November 23, 2015 19:56
Launchy configurations

evs C:/Program Files (x86)/Evernote/Evernote/ENScript.exe showNotes /q "$$"

evn C:\Program Files (x86)\Evernote\Evernote\Evernote.exe /NewNote

cmd C:\Windows\System32\cmd.exe

@filviu
filviu / go.md
Last active November 26, 2015 10:19
Deploy my homeshick based dotfiles

How to run

curl -s https://gist.githubusercontent.com/silviuvulcan/219034b94be99ec38fb2/raw/hsdeploy.sh | bash
@filviu
filviu / launch.sh
Created November 12, 2015 13:13
Launch multiple commands in the background
for i in $(seq 10); do command ARG1 ARG2 > output_$i.txt 2>&1 & sleep $(($RANDOM %3));done
@filviu
filviu / deploy.sh
Last active January 15, 2016 17:24
Script that helps me deploy virtual machines
#!/bin/bash
LV="$1"
distros=( el6 el7 )
LOG="$HOME/deploy.log"
if type tput >/dev/null 2>&1; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)