Skip to content

Instantly share code, notes, and snippets.

@mshock
mshock / list_vols.bat
Created April 24, 2013 16:55
Windows cmd list disk volumes metadata
echo list volume | diskpart
@mshock
mshock / remove_dups.pl
Created April 22, 2013 04:49
remove duplicate records from tab delimited text file and log duplicates per file in directory TODO make dynamic
#! perl -w
use strict;
opendir( DIR, '.' );
my @files = readdir(DIR);
closedir DIR;
for my $file (@files) {
next unless $file =~ m/.*upd$/i;
print "$file...";
@mshock
mshock / julian2ymd.pl
Created April 21, 2013 00:36
Perl sub converts a Julian date number (JDN) into its Gregorian year, month, day, components not 100% precise for JDN too far in the past, but seems good for modern dates (algorithm & constants from Wikipedia)
# convert julian date number into Gregorian year, month, day parts
# not precise too far in the past... 1580-something?
sub jdn2greg {
my ($jdate) = @_;
# make sure formatted like JDN (DDDDDDD[.D*])
return if $jdate !~ m/^\d{7}\.?(\d*)$/;
# TODO add support for time here based on fractional day RH side of decimal place
# define conversion constants
my $y = 4716;
@mshock
mshock / julianify.pl
Created April 20, 2013 23:57
takes Gregorian (Y,M,D) and converts to Julian date number using purely arithmetic (from algorithm on wikipedia)
# calculate JDN from YMD
sub julianify {
my ( $year, $month, $day ) = @_;
my $a = int( ( 14 - $month ) / 12 );
my $y = $year + 4800 - $a;
my $m = $month + 12 * $a - 3;
return
$day
+ int( ( 153 * $m + 2 ) / 5 )
@mshock
mshock / schtasks.bat
Created April 18, 2013 15:23
Windows task manager: change created tasks using CLI
SCHTASKS /change /?
@mshock
mshock / nest_new.jss
Created March 19, 2013 18:11
Google script to nest Gmail labels on the fly as they are archived (I found that nesting labels in the inbox looks cluttered, the intended purpose is for searching/filtering archived mail anyway) requires a filter that applies a "New" label to all incoming e-mail this label can then be hidden
function nest_new() {
var new_label = GmailApp.getUserLabelByName('New');
var regex_nested = new RegExp(/^[\w\s]+\//);
var new_threads = new_label.getThreads();
for (var i = 0; i < new_threads.length; i++) {
Logger.log(1);
var thread_labels = new_threads[i].getLabels();
var inbox_flag = 0;
for (var k = 0; k < thread_labels.length; k++) {
if (thread_labels[j].getName() == 'Inbox') {
@mshock
mshock / kill_tasks.bat
Created March 14, 2013 21:02
force kill application by user in Windows
taskkill /fi "USERNAME eq [domain]/username" /im image_name /f
@mshock
mshock / rsync.bash
Created March 13, 2013 23:45
basic rsync syntax for a backup
#! bash
rsync -vvan --exclude-from=excludes.txt --ignore-existing source/path target/path
# extra verbose and dryrun, -vvn
# archive mode, -a
# create excludes.txt with skip patterns (and/or inversely, --include-from)
# don't overwrite files, --ignore-existing
@mshock
mshock / nested_labels.jss
Created March 13, 2013 01:27
adds parent labels to all nested gmail labels possible timeout, may need to be batched for large numbers of threads I found it unusual that Google didn't have this functionality implemented for nested labels... this makes it much easier to filter by hierarchy
function parent_label() {
var labels = GmailApp.getUserLabels();
var regex_nested = new RegExp(/^[\w\s]+\//);
for (var i = 0; i < labels.length; i++) {
var name = labels[i].getName();
if (!name.match(regex_nested)) continue;
var names = name.split("/");
if (names && names.length > 0) {
var threads = labels[i].getThreads();
var num_threads = threads.length;
@mshock
mshock / archive_label.jss
Last active December 14, 2015 19:38
google script (JavaScript) for archiving e-mails older than specified number of days for a particular label useful for automatically cleaning up any subscriptions, feeds, newsgroups, etc. modified from http://www.johneday.com/422/time-based-gmail-filters-with-google-apps-script significant change - rather than iterating over all threads, only it…
function label_archive() {
var delayDays = 1;
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-delayDays);
var label = GmailApp.getUserLabelByName("label name");
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
if (threads[i].getLastMessageDate()<maxDate)
{
var labels = threads[i].getLabels();