Skip to content

Instantly share code, notes, and snippets.

View CommanderPho's full-sized avatar

Pho Hale CommanderPho

View GitHub Profile
@obeattie
obeattie / datetime_range.py
Created October 19, 2009 12:31
A datetime range class for Python, for (obviously) dealing with ranges of datetimes.
"""Provides a `DateTimeRange` class, which is used for managing ranges of datetimes."""
import datetime
class DateTimeRange(object):
"""Represents a range of datetimes, with a start and (optionally) an end.
Basically implements most of the methods on a standard sequence data type to provide
some lovely syntactic sugar. Specifically, you can iterate on this, index it, slice it,
use the in operator, reverse it, and use it in a boolean context to see if there is any
time in between the start and end."""
@pazdera
pazdera / gist:1098119
Created July 21, 2011 20:25
Singleton example in C++
/*
* Example of a singleton design pattern.
* Copyright (C) 2011 Radek Pazdera
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
@g-r-a-v-e-l-y
g-r-a-v-e-l-y / move-torrent-files-folder-action.applescript
Last active November 4, 2022 18:56
An applescript folder action that moves downloaded torrent files to a different directory.
on adding folder items to thisFolder after receiving added_items
mount volume "afp://user@host/share"
delay 1
repeat with addedFile in added_items
tell application "Finder"
if (the name of the addedFile ends with "torrent" or "nzb") then
display notification "Queueing " & (name of addedFile) & "."
try
tell application "Finder"
move addedFile to "spool" with replacing
@sdanna
sdanna / ComboNumericHeaderCell.cs
Created May 4, 2012 19:13
Winforms DataGridView Column with a custom header (Combobox + NumericUpDown control in this instance)
public class ComboNumericHeaderCell : DataGridViewColumnHeaderCell
{
public readonly ComboBox _comboBox;
public readonly NumericUpDown _numericUpDown;
public ComboNumericHeaderCell()
{
_comboBox = new ComboBox();
_numericUpDown = new NumericUpDown();
_comboBox.Font = Control.DefaultFont;
@tacaswell
tacaswell / simp_zoom.py
Last active February 12, 2023 07:19
factory for adding zoom callback to matplotlib graphs
import matplotlib.pyplot as plt
def zoom_factory(ax,base_scale = 2.):
def zoom_fun(event):
# get the current x and y limits
cur_xlim = ax.get_xlim()
cur_ylim = ax.get_ylim()
# set the range
cur_xrange = (cur_xlim[1] - cur_xlim[0])*.5
@jaivikram
jaivikram / getVideoDetails.py
Last active April 18, 2020 13:02
Python gist to obtain video details like duration, resolution, bitrate, video codec and audio codec, frequency using 'ffmpeg'
#! /usr/bin/env python
import os
import sys
import re
import tempfile
def getVideoDetails(filepath):
tmpf = tempfile.NamedTemporaryFile()
os.system("ffmpeg -i \"%s\" 2> %s" % (filepath, tmpf.name))
lines = tmpf.readlines()
@durden
durden / signal_disconnect.py
Last active May 24, 2022 07:22
Context manager to temporarily disconnect a pyqt signal
from contextlib import contextmanager
@contextmanager
def slot_disconnected(signal, slot):
"""
Create context to perform operations with given slot disconnected from
given signal and automatically connected afterwards.
usage:
@sowenjub
sowenjub / import_notes_app_to_evernote.applescript
Last active August 26, 2021 03:39 — forked from pdxmph/import_notes_app_to_evernote.applescript
Updated to import the modification date as well since that's how notes are sorted in Note.app
tell application "Notes"
set theNotes to every note of the folder "Notes"
repeat with thisNote in theNotes
set myTitle to the name of thisNote
set myText to the body of thisNote
set myCreateDate to the creation date of thisNote
set myUpdateDate to the modification date of thisNote
tell application "Evernote"
set theTransferredNote to create note with html myText ¬
title myTitle ¬
@rwilcox
rwilcox / github_remove_relative_date_greasemonkey.user.js
Last active June 12, 2024 18:25
Remove Github's relative date
// ==UserScript==
// @name Github remove relative date stupidness
// @namespace http://www.wilcoxd.com
// @include https://github.com*
// @version 1
// @grant none
// ==/UserScript==
// created: WD-rpw 03-25-2013
@ichramm
ichramm / gmtime.lua
Created May 29, 2013 22:17
Lua function that returns the current time in UTC.
--[[!
-- @return The current time in UTC
--]]
function gmtime()
return os.time(os.date("!*t"));
end