Skip to content

Instantly share code, notes, and snippets.

@brentmaxwell
brentmaxwell / UnixTimeExtensions.cs
Created March 17, 2015 19:18
Extensions to convert Unix time to DateTime
namespace System
{
public static class UnixTimeExtensions
{
public static long ToUnixTime(this DateTime datetime)
{
return (long)(datetime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
}
public static DateTime FromUnixTime(long time)
@brentmaxwell
brentmaxwell / rowcounts.sql
Created March 17, 2015 19:21
Get *approximate* row counts of all tables in a db
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.ROWS)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U' AND
si.id = OBJECT_ID(so.name)
GROUP BY so.name ORDER BY so.name
@brentmaxwell
brentmaxwell / BinaryIPfunctions.sql
Created March 30, 2015 13:35
IP Address conversions in SQL
CREATE FUNCTION [StringIpToBin]
(
@StringIp VARCHAR(15)
)
RETURNS BINARY(4)
AS
BEGIN
RETURN
CAST(CAST(PARSENAME(@StringIp,4) AS INT) AS BINARY(1)) +
CAST(CAST(PARSENAME(@StringIp,3) AS INT) AS BINARY(1)) +
@brentmaxwell
brentmaxwell / GpsTimeExtensions.cs
Created April 1, 2015 17:03
Extensions for GPS time
namespace System
{
public static class GpsTime
{
public static int ToGpsTimeWeekNumber(this DateTime datetime)
{
DateTime datum = new DateTime(1980, 1, 6, 0, 0, 0);
TimeSpan difference = datetime.Subtract(datum);
return (int)(difference.TotalDays / 7);
}

Keybase proof

I hereby claim:

  • I am brentmaxwell on github.
  • I am brentmaxwell (https://keybase.io/brentmaxwell) on keybase.
  • I have a public key whose fingerprint is 48FC FD01 403C F2AD 5B24 2924 755D 8989 5912 D6FA

To claim this, I am signing this object:

@brentmaxwell
brentmaxwell / openpgp.txt
Created January 14, 2016 01:34
OpenKeychain Linked Identity
This Gist confirms the Linked Identity in my OpenPGP key, and links it to this GitHub account.
Token for proof:
[Verifying my OpenPGP key: openpgp4fpr:48fcfd01403cf2ad5b242924755d89895912d6fa]
@brentmaxwell
brentmaxwell / gist:4e0239b214f589cc3d80824a4bef8f34
Created May 4, 2016 12:53 — forked from davidnunez/gist:1404789
list all installed packages in android adb shell
pm list packages -f
@brentmaxwell
brentmaxwell / DelimitedStringToTable.sql
Last active April 5, 2017 15:10
Delimited string to table
CREATE FUNCTION [dbo].[DelimitedStringToTable]
(
        @String nvarchar(MAX),
        @Delimiter nvarchar(1)
)
RETURNS @Items TABLE
(
        Item nvarchar(50)
)
AS
@brentmaxwell
brentmaxwell / aprs.php
Created September 16, 2015 19:08
Simple PHP page to post to APRS-IS
<?php
$aprs_php_ver = "0.1";
$aprs_is_url = "http://srvr.aprs-is.net:8080";
date_default_timezone_set('UTC');
$defaultSSID = "10";
$defaultPath = "APRS,WIDE2-2,TCPIP*";
if($_SERVER["REQUEST_METHOD"] == "POST")
{
@brentmaxwell
brentmaxwell / AutoMapperConfig.cs
Last active December 6, 2017 14:27
Put automapper configs in model classes NOTE THIS DOES NOT WORK WITH THE LATEST VERSION OF AUTOMAPPER
public class AutoMapperConfig
{
/// <summary>
/// Function that is called in the Global.asax file
/// Runs through and calls each of the functions below, registering the various mappings
/// </summary>
public static void Execute()
{
RegisterOtherMaps();
RegisterMapperHelpers();