Skip to content

Instantly share code, notes, and snippets.

View xivSolutions's full-sized avatar

John Atten xivSolutions

View GitHub Profile
@xivSolutions
xivSolutions / gist:6258586
Created August 17, 2013 20:38
Coding styles used in original Massive vs. alpha revisions
// 1. Coding Style?
// RUBY STYLE Your newer additions seem to take on a Ruby-like (2 space indent) style:
public static void CloneFromObject(this object o, object record) {
var props = o.GetType().GetProperties();
var dictionary = record.ToDictionary();
foreach (var prop in props) {
var propName = prop.Name;
foreach (var key in dictionary.Keys) {
@xivSolutions
xivSolutions / gist:6258658
Created August 17, 2013 20:54
Massive - Originally can grab provider name from connection object, if provided, with default set to System.Data.SqlClient. Removed in alpha branch?
public DynamicModel(string connectionStringName, string tableName = "",
string primaryKeyField = "", string descriptorField = "") {
TableName = tableName == "" ? this.GetType().Name : tableName;
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
DescriptorField = descriptorField;
var _providerName = "System.Data.SqlClient";
// --->>> This is not present in alpha version - leaving for now:
if (!string.IsNullOrWhiteSpace(ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName))
_providerName = ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName;
@xivSolutions
xivSolutions / gist:8294725
Last active January 2, 2016 11:09
Crude pg SQL to select Foreign Key relationships in Db
SELECT
parent.table_name parent,
parent.constraint_name key_name,
tc.constraint_type key_type,
(SELECT c.table_name
FROM information_schema.table_constraints c
WHERE c.constraint_name = parent.constraint_name) child,
(SELECT pid.column_name
FROM information_schema.constraint_column_usage pid
WHERE pid.constraint_name = parent.constraint_name) pid,
@xivSolutions
xivSolutions / gist:8497272
Last active January 3, 2016 17:39
Postgres Table Primary Keys: retrieves the primary keys for the user tables in the database (or filter with additional WHERE criteria). Includes composite primary key columns
SELECT
ctu.table_name table_name,
ctu.constraint_name key_name,
ccu.column_name
FROM information_schema.table_constraints tc
INNER JOIN information_schema.constraint_table_usage ctu
ON ctu.constraint_name = tc.constraint_name
INNER JOIN information_schema.constraint_column_usage ccu
ON ccu.constraint_name = ctu.constraint_name
WHERE tc.constraint_type = 'PRIMARY KEY'
@xivSolutions
xivSolutions / gist:8498452
Last active January 3, 2016 17:49
pg Table Foreign Key Relations, includes composite PKs
SELECT
tc.constraint_name key_name,
ctu.table_name parent_table,
tc.table_name child_table,
(SELECT kcu2.column_name
FROM information_schema.table_constraints tc2
INNER JOIN information_schema.Key_column_usage kcu2
ON tc2.table_name = kcu2.table_name AND tc2.constraint_name = kcu2.constraint_name
WHERE tc2.constraint_type = 'PRIMARY KEY' AND tc2.table_name = ctu.table_name) parent_id,
(SELECT kcu.column_name
@xivSolutions
xivSolutions / gist:8500644
Created January 19, 2014 05:01
pg Tables
SELECT * FROM Information_schema.tables t
WHERE t.table_schema NOT In('information_schema', 'pg_catalog');
@xivSolutions
xivSolutions / gist:8661922
Created January 28, 2014 03:41
JavaScript Timer Function
var start = process.hrtime();
var elapsed_time = function(note){
var precision = 3; // 3 decimal places
var elapsed = process.hrtime(start)[1] / 1000000; // divide by a million to get nano to milli
console.log(process.hrtime(start)[0] + " s, " + elapsed.toFixed(precision) + " ms - " + note); // print message + time
start = process.hrtime(); // reset the timer
}
// Example:
@xivSolutions
xivSolutions / gist:8662057
Created January 28, 2014 04:01
Postgres wildcard "search" SQL Example
CREATE OR REPLACE FUNCTION searchcustomers(text) RETURNS SETOF customers AS $$
SELECT * FROM customers WHERE (last_name ILIKE $1 ||'%');
$$ LANGUAGE SQL;
SELECT * FROM searchcustomers('GR') AS t1;
// LOGIN PARTIAL:
// Change the Views => Shared => _LoginPartial to match this:
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
@xivSolutions
xivSolutions / gist:9166395
Created February 23, 2014 03:25
Massive Bulk Insert
INSERT INTO Transactions (Amount,Comment)
VALUES (@0,@1),(@2,@3),(@4,@5),(@6,@7),(@8,@9),(@10,@11),(@12,@13),(@14,@15),(@16,@17),(@18,@19)