Skip to content

Instantly share code, notes, and snippets.

@josephkern
josephkern / emacs-in-thirty-days-1.el
Created August 24, 2011 16:29
emacs-in-thirty-days-1
; Welcome to the first installment of emacs-command-a-day. Learning
; emacs can be hard as there are many commands and key-bindings that
; beginners find difficult. To help you make the transition to "the
; best text editor ever", I'll bring you one command each week day, so
; you can practice on your own at a reasonable pace.
;; Emacs Installation Notes
; I assume that you can start emacs. If you have no idea how, (on a
; mac or linux system) you should be able to open up a terminal and
@josephkern
josephkern / bloom.py
Created June 8, 2012 19:04
A Simple Bloom Filter in Python
#!/usr/bin/env python
"""A simple Bloom Filter implementation
Calculating optimal filter size:
Where:
m is: self.bitcount (how many bits in self.filter)
n is: the number of expected values added to self.filter
k is: the number of hashes being produced
(1 - math.exp(-float(k * n) / m)) ** k
http://en.wikipedia.org/wiki/Bloom_filter
"""
@josephkern
josephkern / fizzbuzz.py
Created November 16, 2012 15:12
Python FizzBuzz
import sys
def is_3(n):
if not n % 3:
return True
def is_5(n):
if not n % 5:
return True
function Get-ADMemberOf {
# A fast and accurate way of determining all of the groups
# one or more users are part of, especially useful when the groups are nested.
# Example:
# import-module ActiveDirectory
# get-aduser <username> | Get-MemberOf | ft
param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
@josephkern
josephkern / Get-CASServer.ps1
Created September 2, 2015 11:33
A Powershell cmdlet to help discover which CAS Server a user has been using (Requires Exchange Management Shell)
function Get-CASServer {
<#
.SYNOPSIS
A Powershell cmdlet to help discover which CAS Server a user has been using
(Requires Exchange Management Shell to be running during execution)
.PARAMETER Alias
The exchange user alias.
Will take pipeline input from get-mailbox.
.EXAMPLE
Get-Mailbox joseph.kern | Get-CASServer |
@josephkern
josephkern / Get-PrintersAndPorts.ps1
Created July 20, 2017 15:53
Map Windows Server Printers to Port Names
function GetPrintersAndPorts {
foreach ($printer in $(Get-Printer)) {
Get-PrinterPort -Name $printer.PortName | select @{name='Printer';expression={$printer.Name}}, PrinterHostAddress
}
}
@josephkern
josephkern / GetNestedGroups.ps1
Last active July 20, 2017 16:17
Recursively enumerate nested groups in AD
function getgroups ($object) {
### Example: getgroups -object somename.lastname | select name -unique
Get-ADPrincipalGroupMembership $object | Foreach {
$_
Get-ADPrincipalGroupMembership $_
}
}
function GetPortsandPrinters {
$printers = Get-Printer
@josephkern
josephkern / example_image_utils.py
Last active July 29, 2023 10:44 — forked from turicas/example_image_utils.py
Layer on top of Python Imaging Library (PIL) to write text in images easily
#!/usr/bin/env python
# coding: utf-8
# You need PIL <http://www.pythonware.com/products/pil/> to run this script
# Download unifont.ttf from <http://unifoundry.com/unifont.html> (or use
# any TTF you have)
# Copyright 2011 Álvaro Justen [alvarojusten at gmail dot com]
# License: GPL <http://www.gnu.org/copyleft/gpl.html>
from image_utils import ImageText