Skip to content

Instantly share code, notes, and snippets.

@adejones
adejones / checkmount.sh
Last active Nov 26, 2015
Check a mount point on Linux, attempt some recovery if the directory contains files then attempt mount -a
View checkmount.sh
#!/usr/bin/env sh
# check if share is mounted, attempt recovery and remount
if [ -z "$1" ]; then
echo "Usage: $0 /mount/point/to/check"
exit 0
fi
DIR="$1"
View Create new Mercurial repository from a sub directory of an existing repository.sh
# cd to the full repo directory
cd path/to/full_repo
# export tracked files in sub directory by creating a filemap
export SUBDIR=name_of_subdir
hg locate -I "$SUBDIR" | awk '{print "include \"" $1 "\"";}' > ../filemap.txt
echo "rename \"$SUBDIR\" ." >> ../filemap.txt
# create new repo using filemap
hg convert --filemap ../filemap.txt . ../new_repo_name
View Create new Mercurial repository from a sub directory of an existing repository.bat
rem cd to the full repo directory
cd path\to\full_repo
rem export tracked files in sub directory by creating a filemap using an intermediary temp file
set SUBDIR=name_of_subdir
hg locate -I "%SUBDIR%" > ..\filemap.tmp
for /f "tokens=*" %A in (..\filemap.tmp) do @echo include %A >> ..\filemap.txt
echo rename "%SUBDIR%" . >> ..\filemap.txt
del ..\filemap.tmp
@adejones
adejones / filerotator.py
Last active Jan 27, 2020 — forked from RWJMurphy/filerotator.py
Python class and utility for file rotation. Configurable daily, weekly and monthly retention; can use hard links to save space; supports `argparse` config files.
View filerotator.py
#!/usr/bin/env python3
# vim: ft=python ts=4 sw=4 expandtab
#
# Copyright (c) 2013 Reed Kraft-Murphy <reed@reedmurphy.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
View basic_logging.py
import logging
# change default log entry format, set filename and logging level
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", filename="example.log")
logging.info("Started")
logging.info("This is an example entry")
logging.debug("This line won't get logged as the log level is INFO")
logging.info("Done.")
# perform an orderly shutdown by flushing and closing all handlers; called at application exit and no further use of the logging system should be made after this call.
logging.shutdown()
View slightly_less_basic_logging.py
import logging
import logging.handlers
# log file name and logging message level
log_file_name = 'loggingexample.log'
log_level = logging.INFO
# log record format string
format_string = '%(asctime)s %(name)s %(levelname)s %(message)s'
View example-TimedRotatingFileHandler.py
#!/usr/bin/env python
#-------------------------------------------------------------------------------
# Name: example-TimedRotatingFileHandler.py
# Purpose: Write log using TimedRotatingFileHandler
# Author: Adrian Jones
# Created: 2012-05-25
#
# TimedRotatingFileHandler: from handler.py source:
# Current 'when' events supported:
# S - Seconds
@adejones
adejones / wine-app-with-xquartz.app
Created Feb 21, 2017
Script for Wine app using XQuartz. Open up Apple's Script Editor * Edit the program per the directions in the lines that start with -- * if everything is default, you only need to edit the "set toRun" line * After you have edited it for your program, save it as an "Application" (not a script) in the script editor * this will create a .app for yo…
View wine-app-with-xquartz.app
on run
--edit this to be the correct location and file to run (typically only edit after the "drive_c")
set toRun to "$WINEPREFIX/drive_c/Program Files/MyProgram/MyProgramName.exe"
--edit winePrefix if you are not using the default prefix
set winePrefix to "$HOME/.wine"
--edit wineLocation if your wine install is not the default location
set wineLocation to "/usr/local/bin"
@adejones
adejones / wine-app-with-mac-driver.script
Last active May 18, 2018
Script for Wine app using mac driver (now default) - open up Apple's Script Editor, edit , save as Application
View wine-app-with-mac-driver.script
on run
--edit this to be the correct location and file to run (typically only edit after the "drive_c")
set toRun to "$WINEPREFIX/drive_c/Program Files/MyProgram/MyProgramName.exe"
--edit winePrefix if you are not using the default prefix
set winePrefix to "$HOME/.wine"
--edit wineLocation if your wine install is not the default location
set wineLocation to "/usr/local/bin"
View flac2alac.sh
#!/bin/sh
ffmpeg -i “$1″ -acodec alac “`basename “$1″ .flac`.m4a” \
-metadata title=\”"$(metaflac –show-tag=TITLE “$1| sed ‘s/title=//g’)”\” \
-metadata author=\”"$(metaflac –show-tag=ARTIST “$1| sed ‘s/artist=//g’)\” \
-metadata album=\”"$(metaflac –show-tag=ALBUM “$1| sed ‘s/album=//g’)”\” \
-metadata year=\”"$(metaflac –show-tag=DATE “$1| sed ‘s/date=//g’)\” \
-metadata track=\”"$(metaflac –show-tag=TRACKNUMBER “$1| sed ‘s/tracknumber=//g’)”\” \
-metadata genre=\”"$(metaflac –show-tag=GENRE “$1| sed ‘s/genre=//g’)\”
You can’t perform that action at this time.