Skip to content

Instantly share code, notes, and snippets.

@Erreinion
Erreinion / HTMLClipboard.py
Last active November 24, 2023 22:35
HTMLClipboard with updates for Python 3. Includes exception handling for locked clipboard. Improvement of: http://code.activestate.com/recipes/474121/
"""
Created on Sep 24, 2013
@author: RandomHardcoreJerks
Requires pywin32
original: http://code.activestate.com/recipes/474121/
# HtmlClipboard
@Erreinion
Erreinion / gist:6147743
Last active December 20, 2015 14:38
Example of 'private' function in Python. _ = don't expose, __ = hide. http://stackoverflow.com/a/70900/1060378
class Foo(object):
def __init__(self):
self.__baz = 42
def foo(self):
print self.__baz
class Bar(Foo):
def __init__(self):
super(Bar, self).__init__()
self.__baz = 21
@Erreinion
Erreinion / gist:6117932
Created July 30, 2013 23:19
Get username from email address: use split
foo = "john@example.com"
foo.split('@')[0]
@Erreinion
Erreinion / gist:6022554
Created July 17, 2013 17:19
Remotely rename local account names, array iteration,
$comps = @("comp2", "comp1")
$comps | Foreach {
if(Test-Connection $_ -q -count 1){
$user = Get-WMIObject Win32_UserAccount -computername $_ -Filter "Name='@oldname'"
$result = $user.Rename('@newname')
if ($result.ReturnValue -eq 0) {
return Get-WMIObject Win32_UserAccount -computername $_ -Filter "Name='@newname'"
}
}
$user = Get-WMIObject Win32_UserAccount -Filter "Name='$oldName'"
$result = $user.Rename($newName)
if ($result.ReturnValue -eq 0) {
return $user
# you may just print a message here
}
@Erreinion
Erreinion / gist:6022121
Created July 17, 2013 16:21
Get 10 random records from SQL - different set of 10 every time it is run.
SELECT TOP 10 *
FROM Table
ORDER BY NEWID()