Badges

Types

Formats

Show Only

Awk Command
https://mreschke.com/225/awk-command
See also and Awk is a very powerfull line editor filter or small programming language available in all unix style operating systems. This page contains small tutorial awk scripts and snippets. Columns are automatically assigned $1 - $n. And $0 is the entire line Awk has some built in functions: gsub(r,s) globally replaces r with s within the line ($0) index(s,t) returns first position of string t in s (or 0 if not present) length(s) returns the number of characters in s match(s,r...
|
post #225 by mreschke Dec 4th 2010 (6837 views)
PHP Snippets
https://mreschke.com/244/php-snippets
Small miscellaneous PHP code snippets and scripts while (list($key, $value) = each($_POST)) { echo "$key - $value"; }
|
post #244 by mreschke Apr 14th 2011 (2358 views)
Regular Expressions
https://mreschke.com/238/regular-expressions
http:msdn.microsoft.com/en-us/library/ms972966.aspx http:www.4guysfromrolla.com/articles/022603-1.aspx I have a large html file, I want to remove anything between the tags, even if the contents is on multiple lines. There is a regex option called RegexOptions.MultiLine which I though would work, but its actually the RegexOptions.Singleline below what makes it span multiple lines, see http:msdn.microsoft.com/en-us/library/ms972966.aspx for details on RegexOptions.Singleline. Dim reg As New Regex...
|
post #238 by mreschke Mar 8th 2011 (3274 views)
Sed Command
https://mreschke.com/226/sed-command
See Also and Replace all occurrence's in a file (and write back to the same file) sed -i "s/this/withthis/g" /tmp/somefile Replace output newline (carriage return) with sed ':a;N;$!ba;s/\n/ /g' emailbody="Your Directory`/bin/ls -Rhal $yourdir|sed ':a;N;$!ba;s/\ng'`"
|
post #226 by mreschke Dec 6th 2010 (3268 views)
EmailLogs.vbs
https://mreschke.com/213/emaillogsvbs
This script will email a log file (or any file specified) only if the file is under a certain size. If the file is over that size limit, it will still email, but no log will be attached. See Script does not use parameters, everything is hard coded, so just call the .vbs. Great in a scheduled task to email you a daily log file. Can easily be modified with parameters for various purposes. Option Explicit Dim iMsg, iConf, Flds, pc 'Email vars Dim logFile, maxLogSize 'Log vars Dim FSO, File, strSiz...
|
post #213 by mreschke Nov 10th 2010 (2813 views)
StartStopProc.vbs
https://mreschke.com/212/startstopprocvbs
This script will start or stop a process by process name. If the process is already running with a start is called, it will not start a duplicate. The benefit is that it will NOT start the script twice. So if you want to ensure an application is running all the time, just setup a scheduled task to run this script every 10 minutes, if the .exe dies it will start it, if the .exe is still running, it won't start a duplication. REM Example Script.bat (note I path to the .exe dir so it runs in its l...
|
post #212 by mreschke Nov 10th 2010 (2593 views)
DeleteOldFiles.vbs
https://mreschke.com/211/deleteoldfilesvbs
This script will recursively delete all files in every subfolder older than X days. Will not delete any folders, just files. I create a batch file and call the vbs script for any directory I need purged. rem Use this script to clean up any old files automatically. rem This .bat will be called weekly from a scheduled task, and will rem call the d:\production\batch\generic\DeleteOldFiles.vbs with directory/day parameters rem the commands will not run simultaneously (unless they begin with start)...
|
post #211 by mreschke Nov 10th 2010 (5060 views)
Adjust iFrame Height
https://mreschke.com/171/adjust-iframe-height
http:blogs.x2line.com/al/articles/315.aspx Instead of onclick, I am going to add a function AdjustHeight to the onload of the body of the child frame And add this function the the iframe aspx page. Doesn't work for me yet because my iframe is nested in a DetailRow So I have to find the correct name for the iframe. function AdjustHeight() { parent.document.getElementById('ifrForms').style.height = document.body.scrollHeight } Javascript Tip: Adjust iframe Size to Fit its Contents Sometimes we put...
|
post #171 by mreschke Jan 7th 2010 (3330 views)
Recursive File Search or List in .NET
https://mreschke.com/153/recursive-file-search-or-list-in-net
I am sure you all have your functions for a recursive directory/file listing, or file searching by wildcard function for .net, but here is another one, works great. I use it to get a list of all *.aspx pages in a project like this. Dim baseDirectory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(“c:\projects\SSO\”) Dim x As New DSF.SSO.Other.FileSearch(baseDirectory, "*.aspx") Dim pageName As String = "" x.Search(, "*.aspx") lblMessage.Text = "" For Each f As System.IO.FileInfo In...
|
post #153 by mreschke Sep 10th 2009 (3073 views)
Batch File Snippets
https://mreschke.com/124/batch-file-snippets
@echo off FOR /F "TOKENS=1DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B FOR /F "TOKENS=1-5 DELIMS=:" %%d in ("%time%") DO SET h=%%d FOR /F "TOKENS=1-5 DELIMS=:" %%d in ("%time%") DO SET m=%%e FOR /F "TOKENS=1-5 DELIMS=:" %%d in ("%time%") DO SET s=%%f SET dateFilename=%yyyy%-%mm%-%dd%_%h%...
|
post #124 by mreschke Jan 16th 2009 (3175 views)
Javascript Snippets
https://mreschke.com/110/javascript-snippets
Example, loops all checkboxes on page with certain name and alerts if they are checked Note: masterform is the name of my variable for (var i = 0; i < document.masterform.elements.length; i if (document.masterform.elements.type == 'checkbox') { if (document.masterform.elements.name.substring(0, 12) == 'chk_project_') { if (document.masterform.elements.checked) { alert('You Checked: ' } } } } A bit different than looping forms, this will loop all elements (like divs, spans, links...). function t...
|
post #110 by mreschke Sep 25th 2008 (4322 views)
.NET Directory to DataGrid
https://mreschke.com/74/net-directory-to-datagrid
Add a directory of files to a datagrid For greater control, you can , then bind the dataset to the datagrid.
|
post #74 by mreschke Jun 5th 2008 (3404 views)
.NET Directory to Dataset
https://mreschke.com/71/net-directory-to-dataset
This article adds the files in a directory (with wildcards) into a datatable, then to a dataset. With slight modifications to this function you can return the file list as a dataset, datatable or string array. See Private Sub TabArchivesEvents() Dim archivePath As String Dim dirInfo As DirectoryInfo archivePath = System.Configuration.ConfigurationSettings.AppSettings("ExecutiveAnalysisArchivesFolder") & Me.DLR_ID & "\" If Directory.Exists(archivePath) Then dirInfo = New DirectoryInfo(archivePath...
|
post #71 by mreschke May 22nd 2008 (5617 views)
.NET Listbox
https://mreschke.com/62/net-listbox
For i = 0 To lstRecipients.Items.Count - 1 If lstRecipients.Items(i).Selected Then tmp = lstRecipients.Items(i).Value 'This is the selected users ID from tblLogin (not email) lstRecipients.Items(i).Selected = False End If Next
|
post #62 by mreschke May 16th 2008 (2427 views)
ProcessManager.vbs
https://mreschke.com/58/processmanagervbs
Very handy VBScript, watches a process during a certian time interval, if it's running good, if not start it unless it's beyond the time interval, then kill it. Good if you want a program to run between 1pm-5pm but not the rest of the time. Hook this up to a scheduled task and exec every 10 minutes to ensure app is running or app is dead. IF the process is down in the time frame, it will start it, and send out an email that it was down. See You must edit the script below. Must set the process t...
|
post #58 by mreschke May 6th 2008 (3307 views)
VBScript File List
https://mreschke.com/56/vbscript-file-list
<p>This script accepts a path (ex: c:\temp\*.* or c:\*.txt) and builds a 1 dimensional array of the files that match the directory/wildcard.</p>
|
post #56 by mreschke May 6th 2008 (3093 views)
VBScript Snippets
https://mreschke.com/55/vbscript-snippets
dim filesys set filesys=CreateObject("Scripting.FileSystemObject") If filesys.FileExists("c:\sourcefolder\anyfile.html") Then filesys.MoveFile "c:\sourcefolder\anyfile.html", "c:\destfolder\" End If Get the last modified date and time of a file Private Function FileDateTime(byVal pathname) Dim objFSO, objFile On Error Resume Next Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile(pathname) If Err Then FileDateTime = Null Else FileDateTime = CDate( objFil...
|
post #55 by mreschke May 6th 2008 (3026 views)
VBScript Basics
https://mreschke.com/46/vbscript-basics
function test() dim a a = "Hi there" test = a 'This returns a end function Option Explicit 'Check a process, restart it and send email alert, or kill process depending on time window 'Original script created by NetRes 'Modified by mReschke 2008-04-28 (converted to functions, actions change by time, email enhancements, globals, generic process killer) 'If process is NOT running between start/endHour then restart it and send an email if sendEmail = true 'If process is running outside of start/end...
|
post #46 by mreschke Apr 29th 2008 (3144 views)
Send Email using VBScript
https://mreschke.com/45/send-email-using-vbscript
This is just a function snippet, sends an email with attachments, must manually edit function with email and attachment parameters. Used in and Sub SendLogEmail() Set pc = CreateObject("Wscript.Network") Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") Set Flds = iConf.Fields Const schema = "http:schemas.microsoft.com/cdo/configuration/" dim emailBody Flds.Item(schema & "sendusing") = 2 Flds.Item(schema & "smtpserver") = "xxx.xxx.xxx.xxx" Flds.Item(schema & "...
|
post #45 by mreschke Apr 29th 2008 (6005 views)
Daemons and Runlevels
https://mreschke.com/41/daemons-and-runlevels
See LXF 114 p48, 'Banish Your Daemons' Runlevels are defined levels in which a linux operating system can start. Daemons (or services) are scripts/programs that run in the background constantly (like apache or mysql are services that are always running) and are usually executed at startup by the defined runlevel. Runlevels are identified by a number from 0 - 6, but each linux distribution may use those numbers a bit differently. Basically a runlevel determines which daemons to execute at startu...
|
post #41 by mreschke Apr 12th 2008 (13212 views)
Showing 1 to 20 of 20 results