Skip to content

Instantly share code, notes, and snippets.

View mjul's full-sized avatar

Martin Jul mjul

View GitHub Profile
@mjul
mjul / VS-command-prompt.ps1
Created December 16, 2015 09:35
Add Visual Studio 2015 developer tools to the PowerShell path
#
# Set environment variables for Visual Studio Command Prompt
# The technique is to start a Developer Command Prompt and capture its environment into PowerShell
#
# (VS2013) http://stackoverflow.com/questions/2124753/how-i-can-use-powershell-with-the-visual-studio-command-prompt
# (VS2015) https://github.com/jbake/Powershell_scripts/blob/master/Invoke-BatchFile.ps1
#
# Add this to your $PROFILE file in PowerShell
pushd 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\'
@mjul
mjul / Library.fs
Last active September 4, 2015 14:16
Polyglot F# / C# mixture using F# to easily define Value Types (in the DDD sense - they are realized as .NET classes). Shows using types and discriminated unions from C#.
namespace Functionglot
type Customer = { First : string; Last: string; SSN: uint32; AccountNumber : uint32; }
type Shape =
| Rectangle of width : float * length : float
| Circle of radius : float
| EquilateralTriangle of side : float
| Square of side : float
@mjul
mjul / NDepend.cql
Created April 30, 2015 11:26
NDepend - find ASP.NET web pages not using an authorization service
// <Name>Web pages that do not use the AuthorizationService</Name>
from t in JustMyCode.Types
where t.DeriveFrom("System.Web.UI.Page")
from pl in t.Methods
where pl.SimpleName == "Page_Load"
&& !pl.IsUsingType("Cyberdyne.AuthorizationService")
select new { t, t.BaseClass, pl.SimpleName }
@mjul
mjul / application.py
Created December 10, 2014 12:36
Configure a Python Flask application to use the associated Amazon RDS Postgres (or MySQL) database when running on Elastic Beanstalk (inside Docker).
driver = 'mysql+pymysql://'
driver = 'postgresql+psycopg2://'
app.config['SQLALCHEMY_DATABASE_URI'] = driver \
+ os.environ['RDS_USERNAME'] + ':' + os.environ['RDS_PASSWORD'] \
+'@' + os.environ['RDS_HOSTNAME'] + ':' + os.environ['RDS_PORT'] \
+ '/' + os.environ['RDS_DB_NAME']
@mjul
mjul / flaskloginevents.py
Created October 15, 2014 16:29
Subscribe to Flask-Login log in and log out events.
@flask.ext.login.user_logged_in.connect_via(app)
def when_user_logged_in(sender_app, user):
print "user_logged_in %s" % (user)
@flask.ext.login.user_logged_out.connect_via(app)
def when_user_logged_out(sender_app, user):
print "user_logged_out %s" % (user)
@mjul
mjul / form_to_opencv.py
Created July 2, 2014 19:27
Decode Python (Flask or Werkzeug) photo file uploaded via HTTP POST request in-memory to an OpenCV matrix.
#
# Example from code built on the Flask web framework (and Werkzeug)
# Accepts uploading a photo file in the 'photo' form member, then
# copies it into a memory byte array and converts it to a numpy array
# which in turn can be decoded by OpenCV.
#
# Beware that this increases the memory pressure and you should
# configure a max request size before doing so.
#
# It saves a round-trip to a temporary file, though.
@mjul
mjul / gist:6932208
Created October 11, 2013 09:43
Base class (shudder) for unit testing .NET exceptions against the exception design guidelines
using System;
using DeveloperTest.TestHelpers;
using NUnit.Framework;
namespace DeveloperTest.Utilities
{
[TestFixture, Unit]
public abstract class ExceptionTestBase<TException> where TException : Exception
{
// According to the design guidelines for exceptions
@mjul
mjul / SQLxmlquery
Created September 24, 2013 14:41
From an XML document in SQL Server, extract the value of an XML node via an XML query. For example, to extract the TransactionId value as a Guid from the Metadata node on an XML document, do this:
SELECT
[Id]
,cast([EventData] as xml)
.value('(/*/*[local-name() = "Metadata"]/*[local-name() = "TransactionId"])[1]', 'uniqueidentifier') as txid
FROM [Playground].[command].[Events]
@mjul
mjul / .gitattributes
Last active December 21, 2015 03:08
GIT .gitignore and .gitattributes for NuGet packages, ensuring that they are checked in completely and exactly as they are downloaded.
# Treat everything under packages as binary, except the config and git config files
* -text
/.gitattributes text=auto
/.gitignore text=auto
/repositories.config text=auto
@mjul
mjul / configure_cqrs_permissions.sql
Created June 28, 2013 11:29
SQL Server set up logins, users and roles for CQRS
--
-- http://dba.stackexchange.com/questions/2572/how-do-i-assign-an-entire-active-directory-group-security-access-in-sql-server-2
--
use master;
CREATE LOGIN [MyDomain\MyCoolApp Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[MyCoolApp];
GO
USE [MyCoolApp];
GO