Skip to content

Instantly share code, notes, and snippets.

View aromig's full-sized avatar
🐧
• • • • • •

Adam Romig aromig

🐧
• • • • • •
View GitHub Profile
@aromig
aromig / myip.sh
Created July 26, 2018 15:43
Displays my ip addresses
#!/bin/bash
# Displays my ip addresses
ifconfig | grep "inet " | cut -f2 -d " "
@aromig
aromig / FindControlRecursive.cs
Created July 13, 2018 17:32
C# Grabbing a Control from a UserControl that's somewhere in a MasterPage
// Digs through the control hierarchy starting at a root control
// stopping when the ID matches
private static Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
return root;
foreach (Control control in root.Controls)
{
@aromig
aromig / nicks_math_problem.js
Created January 17, 2018 22:14
Largest whole number less than 2007 that's divisible by 2, 3, 4, 5, 6, and 7
// My 11 year old's 6th grade homework one day: https://pbs.twimg.com/media/DLVjmkXUEAAF2_D.jpg
// Problem of the Week: Find the largest whole number less than 2007 that is divisible by 2, 3, 4, 5, 6, and 7.
// He wrote down 1680 and wanted me to check to see if he was right.
// Checked it the easiest way I knew.
for (var i = 2007; i > 0; i--)
if (i % 7 == 0)
if (i % 6 == 0)
if (i % 5 == 0)
if (i % 4 == 0)
String.prototype.replaceCharAt = function (index, character) {
return this.substr(0, index) + character + this.substr(index + character.length);
}
function isAnagram(phrase1, phrase2) {
return phrase1.split("").sort().join("") === phrase2.split("").sort().join("");
}
/* Calculates the difference between dates excluding weekends */
ALTER FUNCTION [dbo].[CalculateNumberOfWorkDays] (@StartDate datetime, @EndDate datetime)
RETURNS int
AS
BEGIN
SET @StartDate = DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0)
SET @EndDate = DATEADD(dd, DATEDIFF(dd, 0, @EndDate), 0)
@aromig
aromig / disable_screencapture_dropshadow.sh
Created March 3, 2017 16:23
macOS - Disable Screen Capture Drop Shadows
defaults write com.apple.screencapture disable-shadow -bool true
# Need to restart the UI Server
killall SystemUIServer
@aromig
aromig / robocopy_exclude_existing_files.cmd
Created September 28, 2016 14:47
Robocopy - Exclude Existing Files
robocopy c:\Sourcepath c:\Destpath /E /XC /XN /XO
:: /E makes Robocopy recursively copy subdirectories, including empty ones.
:: /XC excludes existing files with the same timestamp, but different file sizes. Robocopy normally overwrites those.
:: /XN excludes existing files newer than the copy in the source directory. Robocopy normally overwrites those.
:: /XO excludes existing files older than the copy in the source directory. Robocopy normally overwrites those.
:: With the Changed, Older, and Newer classes excluded, Robocopy will exclude files existing in the destination directory.
@aromig
aromig / linq_leftjoins.cs
Last active June 2, 2016 16:53
Entity LINQ to SQL Left Joins
// Example of multiple LEFT OUTER JOINs in LINQ query syntax
// Equivalent of: SELECT <blahblah> FROM requests r LEFT JOIN employees e ON e.emplid = r.emplid LEFT JOIN employees m ON m.emplid = r.mgrid LEFT JOIN locations l ON l.locid = request.locid
using System.Linq;
using (Entities db = new Entities())
{
var rows =
from request in db.requests
from employee in db.employees.Where(e => e.emplid == request.emplid).DefaultIfEmpty()
@aromig
aromig / ExportDataSet.cs
Last active February 16, 2016 21:12
Export a DataSet to Excel or Word
public static void ExportDataSet(DataSet ds, string format, string filename, bool boolGridLines, string caption)
{
// format = "ms-excel", "ms-word"
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd." + format;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + filename);
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw);