Skip to content

Instantly share code, notes, and snippets.

from urllib2 import urlopen
from datetime import timedelta
import re
timedelta_regex = re.compile(r'(?P<days>\d+):(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)')
def get_modem_status(modem_uri="http://192.168.100.1"):
content = urlopen(modem_uri + "/index.cgi?page=modemStatusData").read()
parts = content.split("##")
public Task CreateAsync(ApplicationUser user)
{
if (user == null)
{
throw new ArgumentNullException("user cannot be null.");
}
if (string.IsNullOrEmpty(user.UserName))
{
throw new ArgumentNullException("username cannot be null or empty.");
@blachniet
blachniet / CustomUserValidator.cs
Last active November 3, 2017 04:06
This custom user validator can be used instead of the default user validator in order to require that the UserName property in the IUser be an email address. To use this validator, just set UserManager.UserValidator to a new instance of this class.
/// <summary>
/// A replacement for the <see cref="UserValidator"/> which requires that an email
/// address be used for the <see cref="IUser.UserName"/> field.
/// </summary>
/// <typeparam name="TUser">Must be a type derived from <see cref="Microsoft.AspNet.Identity.IUser"/>.</typeparam>
/// <remarks>
/// This validator check the <see cref="IUser.UserName"/> property against the simple email regex provided at
/// http://www.regular-expressions.info/email.html. If a <see cref="UserManager"/> is provided in the constructor,
/// it will also ensure that the email address is not already being used by another account in the manager.
///
@blachniet
blachniet / pack.ps1
Last active March 16, 2018 11:55
Simple pack script that puts the contents of a C# project build directory into a timestamped folder
$timestamp = Get-Date -Format yyyyMMdd-HHmm
$dir = "pack_$timestamp"
Remove-Item "$dir" -Force -Recurse -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path "$dir"
Get-ChildItem .\* -Include *.md, *.exe, *.exe.config, *.dll -Exclude *.vshost.exe, *.vshost.exe.config |
% { Copy-Item $_ "$dir" }
@blachniet
blachniet / DisposePattern.cs
Last active December 21, 2015 04:29
The dispose pattern.
#region Dispose Pattern
private bool _disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
@blachniet
blachniet / PowerShellQuickies.ps1
Last active January 20, 2019 20:13
A bunch of useful PowerShell snippets.
################################################################################
# Run Files Last Accessed After Date
Get-ChildItem C:\Input |
Select-Object FullName, LastAccessTime |
Where-Object {$_.LastAccessTime -g "01/01/2013"}
%{.\SuperAwesomize.exe $_.FullName}
################################################################################
# Get full path of last file accessed item in directory
# ? is short for Where-Object
@blachniet
blachniet / LoadSqlPowershellModule.md
Last active December 19, 2015 14:09
Loads the sqlps module if the "Invoke-Sqlcmd" cmdlet does not exist.

Loads the sqlps module if the "Invoke-Sqlcmd" cmdlet does not exist. This is the suggested method for loading the module according to MSDN docs. You can download the module installer from here.

@blachniet
blachniet / MSCrap.bat
Created June 18, 2013 12:24
Adding common Microsoft tools to batch files
REM VS2010
CALL "%VS100COMNTOOLS%\vsvars32.bat"
REM VS2012
CALL "%VS110COMNTOOLS%\vsvars32.bat"
@blachniet
blachniet / GetHttpPage.py
Last active December 17, 2015 17:09
Python - Get http stream data from url
import urllib2
url = "http://google.com"
usock = urllib2.urlopen(url)
data = usock.read()
usock.close()
print data
@blachniet
blachniet / pushlog
Last active December 16, 2015 18:39
mimosa + heroku crash
2013-04-29T03:14:23.510263+00:00 heroku[web.1]: Starting process with command `node dist/app.js`
2013-04-29T03:14:24.724186+00:00 app[web.1]:
2013-04-29T03:14:24.724501+00:00 app[web.1]: module.js:340
2013-04-29T03:14:24.724765+00:00 app[web.1]: throw err;
2013-04-29T03:14:24.724895+00:00 app[web.1]: ^
2013-04-29T03:14:24.727523+00:00 app[web.1]: Error: Cannot find module 'debug'
2013-04-29T03:14:24.727523+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2013-04-29T03:14:24.727523+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15)
2013-04-29T03:14:24.727523+00:00 app[web.1]: at Module.require (module.js:364:17)
2013-04-29T03:14:24.727523+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10)