Skip to content

Instantly share code, notes, and snippets.

View xivSolutions's full-sized avatar

John Atten xivSolutions

View GitHub Profile
@xivSolutions
xivSolutions / gist:9359513
Created March 5, 2014 01:33
Overriding Roles and adding JsonIgnore Attribute
public class ApplicationUser : IdentityUser
{
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string Email { get; set; }
@xivSolutions
xivSolutions / gist:9281856
Created February 28, 2014 23:05
currval() Issue in PG
-- A table, "turtles":
CREATE TABLE turtles
(
id serial NOT NULL,
name text,
lastid integer,
CONSTRAINT pk_turtles PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
@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)
// 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: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;
@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: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: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: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: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,