Skip to content

Instantly share code, notes, and snippets.

@jonschoning
jonschoning / move_matches_to_folder.py
Created July 7, 2011 05:51
move_matches_to_folder
def __main():
kwargs={
'source_directory' :r'D:/bin/completeddownloads/docs'
,'search_pattern' :'*Success*'
,'dest_directory_root' :r'D:/Users/qwerty/Documents/_user/Programming/Reference'
,'dest_leaf_directory' :'Success'
}
move_matches_to_folder(**kwargs)
def move_matches_to_folder(source_directory, search_pattern, dest_directory_root, dest_leaf_directory=""):
@jonschoning
jonschoning / move_matches_to_folder2.py
Created July 7, 2011 06:12
move_matches_to_folder2
def __main():
kwargs={
'source_directory' :r'D:/bin/completeddownloads/docs'
,'search_pattern' :'*Success*'
,'dest_directory_root' :r'D:/Users/qwerty/Documents/_user/Programming/Reference'
,'dest_leaf_directory' :'Success'
}
move_matches_to_folder(**kwargs)
def move_matches_to_folder(source_directory, search_pattern, dest_directory_root, dest_leaf_directory=""):
@jonschoning
jonschoning / move_matches_to_folder3.py
Created July 7, 2011 07:07
move_matches_to_folder3
import os,glob
def __main():
kwargs={
'source_directory' :r'D:/bin/completeddownloads/docs'
,'search_pattern' :'*Success*'
,'dest_directory_root' :r'D:/Users/qwerty/Documents/_user/Programming/Reference'
,'dest_leaf_directory' :'Success'
}
move_matches_to_folder(**kwargs)
@jonschoning
jonschoning / fibgen.py
Created July 28, 2011 16:29
Fibonacci numbers, with an one-liner in Python 3?
#Here's an implementation that doesn't use recursion, and only memoizes the last two values instead of the whole sequence history.
#nthfib() below is the direct solution to the original problem (as long as imports are allowed)
#It's less elegant than using the Reduce methods above, but, although slightly different that what was asked for, it gains the ability to to be used more efficiently as an infinite generator if one needs to output the sequence up to the nth number as well (re-writing slightly as fibgen() below).
# from itertools import imap, islice, repeat
# nthfib = lambda n: next(islice((lambda x=[0, 1]: imap((lambda x: (lambda setx=x.__setitem__, x0_temp=x[0]: (x[1], setx(0, x[1]), setx(1, x0_temp+x[1]))[0])()), repeat(x)))(), n-1, None))
@jonschoning
jonschoning / authmode.cs
Created July 28, 2011 16:32
Programmatically determine SharePoint 2007 authentication mode
//Is there a way to programmatically determine if a SharePoint 2007 web application is using Forms authentication? I guess one way might be to read it from the web.config but I was wondering if there is some property exposed in the API.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
string g = base.Request.QueryString["WebAppId"];
this.webApp = (SPWebApplication) SPConfigurationDatabase.Local.GetObject(new Guid(g));
this.zone = (SPUrlZone) Enum.Parse(typeof(SPUrlZone), base.Request.QueryString["Zone"]);
this.lb_Zone.Text = SPHttpUtility.HtmlEncode(SPAlternateUrl.GetZoneName(this.zone));
SPIisSettings iisSettings = this.webApp.IisSettings[this.zone];
@jonschoning
jonschoning / SharePoint2007securityValidation.cs
Created July 28, 2011 16:33
Sharepoint SPWeb rename - Exception SPException - The security validation for this page is invalid
//1) Set SPWeb.AllowUnsafeUpdates = true
//2) You may need to validate the FormDigest with ValidateFormDigest
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (SPWeb thisWeb = site.OpenWeb(webUrl))
{
try
{
thisWeb.AllowUnsafeUpdates = true;
@jonschoning
jonschoning / about.md
Created August 10, 2011 02:13 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@jonschoning
jonschoning / copy_matches_to_folder.py
Created August 11, 2011 18:34
copy_matches_to_folder.py
import os,shutil
def __main():
kwargs={
'source_directory' :r'\\host\everyone\s\GTCom'
,'file_types' :['.jpg', '.gif', '.png', '.tif']
,'dest_directory_root' :r'\\host\everyone\staticfiles'
}
copy_matches_to_folder(**kwargs)
@jonschoning
jonschoning / Remove-DuplicateWebparts.ps1
Created August 16, 2011 14:27
Remove-DuplicateWebparts.ps1
$ErrorActionPreference='stop'
function Remove-DuplicateWebparts
{
param([System.String] $siteurl, [System.String] $filename)
$site = new-object Microsoft.SharePoint.SPSite($siteurl)
$items = $site.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::MasterPageCatalog).Items
$webParts = new-object 'System.Collections.Generic.List[string]'
@jonschoning
jonschoning / ShowAddress.bas
Created August 16, 2011 14:31
ShowAddress.bas
Attribute VB_Name = "ShowAddress"
Public Function ShowAddress(rng As Range) As String
If rng.Cells.Count > 1 Then
ShowAddress = CVErr(xlErrValue)
Else
ShowAddress = rng.Hyperlinks.Item(1).Address
End If
End Function