Skip to content

Instantly share code, notes, and snippets.

@t3knoid
t3knoid / FilteredBindingList.cs
Created February 24, 2019 23:21
Use this class to define a datagridview datasource that is a list. Use this in conjunction with the Microsoft DataGridAutoFilter library to create an automatically filtered datagridview table.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using System.Collections;
using System.Text.RegularExpressions;
namespace FilteredBindingList
@t3knoid
t3knoid / walkAndOrg.py
Created November 26, 2018 14:46
This Python script will walk a specified sourcedir and copies files it finds and copies them into a specified destination folder subfolder using the file's extension
from shutil import copyfile
import os
count = 0
destinationdir = ''
sourcedir = ''
for (dirname, dirs, files) in os.walk(sourcedir):
for file in files:
filename, file_extension = os.path.splitext(file)
file_extension = file_extension.strip(".")
@t3knoid
t3knoid / deleteOldFiles.py
Last active October 9, 2018 14:49
Python script that deletes old files
import os
import datetime
import win32wnet
from datetime import date
# Destination path
host = 'devfs02' # SMB server
share = 'K' # SMB share
username = 'tde' # SMB user
password = 'etech' # SMB user password
@t3knoid
t3knoid / batchRenameFolders.txt
Last active October 4, 2018 19:26
One-liner to batch rename same named folders or files
The following DOS batch one liner will rename many same-named folder folders.
The following example will rename folders under "Reports Test 2\data" that ends with "Custodian1" and renames it to "Custodian2."
for /f "tokens=*" %a in ('dir /b /s "Reports Test 2\data" ^| findstr /r "Custodian1$"') do ren "%a" "Custodian2"
This can be easily customized for example to rename folders or files in the current folder:
for /f "tokens=*" %a in ('dir /b') do ren "%~na" "%~na2"
@t3knoid
t3knoid / gist:6a0b0cad167b43bafe47dc11757c382e
Created May 23, 2018 17:57
Adding version information automatically in Microsoft Word document
The following will provide an automatic way of adding version information into a Microsoft Word document using an external text file. This is an ideal way in versioning documents using external controls such as a build script. The script can update external version file and then create a PDF of the document. Thereby, creating a "build" of the Word document.
1. Add a version.txt file in the same folder as your document. This file will contain a single line with the version information (e.g. 1.0.0)
2. Open the Word document and Add an IncludeText Quick Part.
3. Reveal the field codes by typing ALT-F9
4. Position the cursor after "{ INCLUDETEXT" just before the closing " }" tag.
5. Go to Quick Part and insert a FileName field and tick the "Add path to filename" checkbox.
You should have the following code at this point.
@t3knoid
t3knoid / printHeaderFields.groovy
Created February 20, 2018 21:45
Groovy example of printing groovy header fields after openConnection() call
def NEW_LINE = System.getProperty("line.separator")
if (args.length < 1)
{
println "Enter a URL as an argument."
System.exit(-1)
}
def address = args[0]
def urlInfo = address.toURL()
println "===================================================================="
println "====== HEADER FIELDS FOR URL ${address}"
@t3knoid
t3knoid / getParams.groovy
Created February 20, 2018 20:23
This is an example on how to parse arguments passed to a groovy script
// This is an example on how to parse arguments passed to a groovy script
import jenkins.model.*
if (args.length != 2 ) {
println "Error on arguments!"
}
def jobName = args[0] ?: 'a_job'
def viewName = args[1] ?: 'a_view'
println jobName + ' ' + viewName
@t3knoid
t3knoid / parseJSON.groovy
Created February 14, 2018 17:22
Jenkins Groovy method to parse JSON text
import groovy.json.JsonSlurper
/***
* This method uses JsonSlurper to parse a given JSON text into
* a more accessible data list and map structure. The following
* example illustrates this transformation
*
* def result = slurper.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}')
*
* assert result.person.name == "Guillaume"
@t3knoid
t3knoid / requestConnection.groovy
Last active February 14, 2018 17:35
Jenkins Groovy Web Login RESTful Authentication method
/***
* Use this method to get an authentication token for a given URL and authentication string
* @param auth is an authentication string in the form of username:password or username:authtoken
* @param addr is the url to access
***/
def requestConnection(auth,addr)
{
def authString = "${auth}".getBytes().encodeBase64().toString() // Use authentication token
def conn = addr.toURL().openConnection()
if (authString.length() > 0)
@t3knoid
t3knoid / JenkinsInjectBuildEnvironment.groovy
Created February 13, 2018 23:02
Jenkins Groovy script to inject the current build environment variables into current environment.
// Use the following Groovy script to inject into the current build context
// Install the EnvInject plugin, https://wiki.jenkins.io/display/JENKINS/EnvInject+Plugin.
// In your job, Enable the Inject environment variables to the build process and
// Enter in the Evaluated Groovy script field. Make sure to keep the Use Groovy Sandbox
// unchecked. This script returns a hashmap of all environment variables including
// build specific ones into the current environment.
//
// By doing this, Jenkins specific environment variables can be accessed later on
// in a non=system Groovy script with a simple way. For example, to get the value of the
// JENKINS_URL is done this way: