Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / heeloworld
Created December 14, 2011 19:16
hello world
public void SayHello()
{
for (int i=0; i<10; i++)
{
Console.WriteLine("Hello World")
}
}
@primaryobjects
primaryobjects / gaDelay
Created March 26, 2013 14:35
Google Analytics Event Tracking Delay
$('.gaDelay').click(function (e) {
var element = this;
e.preventDefault();
setTimeout(function () { location = element.href }, 100);
});
@primaryobjects
primaryobjects / gist:6390975
Created August 30, 2013 15:22
Loading a Windows Identity Foundation thumbprint key with a custom ConfurationBasedIsserNameRegistry class. If you have hidden control characters in the thumbprint key, this will filter them out, allowing the cert to be accepted by WIF and SSO.
<issuerNameRegistry type="RelyingParty1.CustomIssuerNameRegistry, RelyingParty1">
<trustedIssuers>
<add thumbprint="abcdefghijklmnopqrstuvwxyz1234567890abcd" name="optional name" />
</trustedIssuers>
</issuerNameRegistry>
using System.IdentityModel.Tokens;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
@primaryobjects
primaryobjects / gist:6929031
Created October 11, 2013 03:11
Auto-sizing a window by height, based on the text contents of a TextBlock in WPF C#. Normally, wrapping a TextBlock in a ScrollViewer will show a vertical scrollbar if the text is too tall for the TextBlock. This handy code automatically resizes the TextBlock and Window height to compensate for the text, so the vertical scrollbar, hopefully, doe…
<ScrollViewer Margin="2,34,0,0" Grid.RowSpan="2" Name="scrollViewer" VerticalScrollBarVisibility="Auto">
<TextBlock Grid.Row="1" x:Name="tbMessage" TextWrapping="Wrap" Text="A long block of overflowing text goes here." />
</ScrollViewer>
private void OnLoaded(object sender, RoutedEventArgs e)
{
// Adjust height of window to match text height. Scroll bars shouldn't show.
if (scrollViewer.ComputedVerticalScrollBarVisibility == System.Windows.Visibility.Visible)
{
scrollViewer.Height += scrollViewer.ScrollableHeight;
@primaryobjects
primaryobjects / gist:8442193
Last active January 13, 2022 09:49
MVC C# .NET: Passing data from a child partial view to the parent page via ViewContext.ViewBag. This example demonstrates how to set the page title from a child partial view.
// In your HTML helper class, include this function:
/// <summary>
/// Returns the ViewBag of the parent page. Allows a child view to access the parent view's ViewBag object. A child view may then set a property accessible by the parent page.
/// </summary>
/// <returns>ViewBag</returns>
public static dynamic GetPageViewBag(this HtmlHelper html)
{
if (html == null || html.ViewContext == null) //this means that the page is root or parial view
{
@primaryobjects
primaryobjects / linkedInLinks.R
Last active July 29, 2024 13:36
Grabs all LinkedIn urls from a Coursera forum thread. Perfect for the "Let's Connect!" threads.
@primaryobjects
primaryobjects / linkedInLinksPlus.R
Created June 27, 2014 17:55
Grabs all LinkedIn urls from a Coursera forum thread. Perfect for the "Let's Connect!" threads.
require(XML)
require(stringr)
#
# Grabs all names and LinkedIn urls from a Coursera forum thread. Perfect for the "Let's Connect!" threads.
# Usage:
# 1. Open a Coursera forum thread, containing LinkedIn links.
# 2. Scroll all the way to the bottom of the page to load all posts in the thread.
# 3. Save the web page to an html file named post.htm.
# 4. Call linkedInLinks("post.htm")
@primaryobjects
primaryobjects / timer.R
Created July 8, 2014 01:52
Calculating the mean of a data table column in R (American Community Survey) and timing the result.
doLoop <- function(method, iterations = 1000) {
for (i in 1:iterations) {
method();
}
}
# Load csv file.
DT <- fread('https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06pid.csv')
# Time option 2.
@primaryobjects
primaryobjects / LinuxMintInstall
Last active October 26, 2015 02:07
Linux Mint Install Notes from a Windows 8 user. This document contains steps to install Linux Mint along-side Windows 8, on a separate partition on the same hard-drive (ie., dual-boot) using just 1 partition (a Linux swapfile will be used instead of a separate partition). It also contains steps to customize the Linux setup to look and feel simil…
1. Download linux distribution iso.
2. Download unetbootin.
3. In Windows 8, right-click start icon and select Disk Management.
4. Select C: drive and click Shrink. Shrink the disk by the amount you want for the linux drive, for example 30GB.
5. Right-click the new unallocated 30GB space and select New Volume. Format it as FAT32 and leave the drive letter blank.
6. Run unetbootin. Select the iso you downloaded in step 1. Select Hard Disk and leave the default disk as C:. This will install a temporary boot of the linux "live" iso, also called a frugal install.
7. Restart the PC and in the boot menu, choose "unetbootin". This will load the linux live environment. Starting might take a while (maybe 10+ minutes). When the linux logo displays, hit any key on the keyboard to show the terminal screen and status. The part, "scanning disc for index files.." may take a long time, so be patient.
8. Once linux starts up, click "Install Linux".
9. Keep clicking Continue until you reach the disk drive partition screen. Sel
@primaryobjects
primaryobjects / loginimage.sh
Last active August 29, 2015 14:05
Linux Mint login background changer. Changes the background image on the Linux Mint theme login screen. To run automatically at each reboot, run this script as: sudo bash loginimage.sh -r. Put the command in /etc/rc.local
#!/bin/bash
appPath=/usr/share/login-image-changer
settingsPath=$appPath/settings.conf
rcLocalPath="/etc/rc.local"
scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
runCommand="sudo bash \"$scriptPath/loginimage.sh\" -r"
settingsExists=0
install=0
uninstall=0