Skip to content

Instantly share code, notes, and snippets.

@PaulDMendoza
PaulDMendoza / program.cs
Created August 14, 2018 23:24
SigParser C# Gmail Full Example
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@PaulDMendoza
PaulDMendoza / decoder.cs
Created August 14, 2018 23:07
SigParser Decoder Example
///<summary>
/// Decode Base64 encoded string with URL and Filename Safe Alphabet using UTF-8.
///</summary>
///<param name="str">Base64 code</param>
///<returns>The decoded string.</returns>
public static string DecodeBase64(string str)
{
if (str == null)
return str;
int padChars = (str.Length % 4) == 0 ? 0 : (4 - (str.Length % 4));
@PaulDMendoza
PaulDMendoza / messages.cs
Last active August 14, 2018 23:06
SigParser Gmail Example
// Define parameters of request.
var request = service.Users.Messages.List("me");
IList<Message> messages = request.Execute().Messages;
Console.WriteLine("Messages:");
if (messages != null && messages.Count > 0)
{
foreach (var message in messages)
{
var messageReq = service.Users.Messages.Get("me", message.Id);
@PaulDMendoza
PaulDMendoza / Response.js
Last active May 26, 2018 17:10
SigParserResponse
{
"isSpammyLookingEmailMessage": false,
"isSpammyLookingSender": false,
"isSpam": false,
"from_LastName": "Gates",
"from_FirstName": "Bill",
"from_Fax": null,
"from_Phone": null,
"from_Address": null,
"from_Title": null,
@PaulDMendoza
PaulDMendoza / Request.js
Last active May 26, 2018 16:12
SigParser - Request
{
"subject": "Thanks for meeting...",
"from_address": "bgates@example.com",
"from_name": "Bill Gates",
"htmlbody": "<div>Hi, good seeing you the other day.</div><div>--</div><div>Bill Gates</div><div>Cell 777-444-8888</div><a href=\"https://www.linkedin.com/in/williamhgates/\">LinkedIn</a><a href=\"https://twitter.com/BillGates\">Twitter</a>",
"plainbody": "Hi, good seeing you the other day. \r\n--\r\nBill Gates\r\nCell 777-444-8888",
"date": "2017-01-01T00:00:00"
}
@PaulDMendoza
PaulDMendoza / Connection.cs
Last active February 18, 2018 02:19
Open Connection Example
public static DbConnection GetCenterConnection(IConfig config = null)
{
return new DragnetTech.Shared.Tracing.Npgsql.NpgsqlConnection(new Npgsql.NpgsqlConnection(Config.GetConnectionStringCenterDB()), Tracing.AWSIDbProfiler.Instance);
}
@PaulDMendoza
PaulDMendoza / AWSIDbProfiler.cs
Last active February 18, 2018 02:17
Profiler for any ADO.NET connection and XRay
/// <summary>
/// This must be called NpgsqlConnection for Dapper to detect the connection as being an NpgsqlConnection.
/// Otherwise Dapper doesn't handle arrays correctly for Postgresql connections.
/// </summary>
public class NpgsqlConnection : StackExchange.Profiling.Data.ProfiledDbConnection
{
public NpgsqlConnection(DbConnection connection, IDbProfiler profiler) : base(connection, profiler)
{
@PaulDMendoza
PaulDMendoza / Postgres2C#Class
Last active March 1, 2024 13:46
Postgresql table to C# class converter
SELECT 'public ' ||
case
when data_type = 'uuid' THEN 'Guid'
when data_type = 'text' then 'string'
when data_type = 'json' then 'string'
when data_type = 'integer' then 'int'
when data_type = 'boolean' then 'bool'
when data_type = 'bigint' then 'long'
when data_type = 'timestamp with time zone' then 'DateTimeOffset'
when data_type = 'timestamp without time zone' then 'DateTime'
@PaulDMendoza
PaulDMendoza / ExamplePostConverted.cs
Last active January 29, 2017 23:04
Visual Studio Find and Replace to convert auto property to set an "_isDirty" flag
Guid _UserID = Guid.Empty;
public Guid UserID { get { return _UserID;} set { _isDirty = true; _UserID = value; } }
string _EmailAddress = null;
public string EmailAddress { get { return _EmailAddress;} set { _isDirty = true; _EmailAddress = value; } }
string _Name = null;
public string Name { get { return _Name;} set { _isDirty = true; _Name = value; } }
int _TimesFound = 0;
public int TimesFound { get { return _TimesFound;} set { _isDirty = true; _TimesFound = value; } }
@PaulDMendoza
PaulDMendoza / Loggly
Created February 17, 2015 03:06
Loggly Simple Swift Logger (requires Alamofire ONLY!!!!)
//
// Loggly.swift
// mobile
//
// Created by Paul Mendoza
// Twitter: PaulDMendoza
//
import Foundation
import UIKit