Skip to content

Instantly share code, notes, and snippets.

View techniq's full-sized avatar

Sean Lynch techniq

View GitHub Profile
@techniq
techniq / audit_mixin.py
Created March 16, 2013 01:05
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
@techniq
techniq / view.py
Created March 16, 2013 01:06
SQLAlchemy View support
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import Executable, ClauseElement
from sqlalchemy.schema import DDLElement, DropTable
from sqlalchemy.sql import table
from sqlalchemy.orm import Query
from . import db
class CreateView(DDLElement):
@techniq
techniq / axis.d.ts
Created December 30, 2018 15:45
@vx typings
declare module '@vx/axis' {
import React from 'react';
import { ScaleTime } from 'd3-scale';
interface Point {
x: number;
y: number;
}
interface AxisProps {
@techniq
techniq / README.md
Last active November 26, 2020 15:32
Convert JSON boolean strings ("true"/"false") to boolean values

Convert undefined to false

JSON.parse(someVariable || false)

Returns

  • "true" => true
  • "false" => false
  • undefined => false
@techniq
techniq / README.md
Last active July 13, 2019 01:39
curl reference

See response headers

curl -i localhost/api/foo

See request and response headers

curl -v localhost/api/foo

POST with string data

Unix:

@techniq
techniq / select2_ajax.js
Created January 23, 2013 16:24
Select2 ajax example with custom query call to append data to the request. Note: Providing ajax settings is not needed (and not used) when query is provided. Left here as a full example.
$("[data-provide='select2']").each(function () {
var $element = $(this);
$element.select2({
placeholder: $element.data("placeholder"),
minimumInputLength: 0,
allowClear: true,
initSelection: function (element, callback) {
callback({
id: $(element).val(),
@techniq
techniq / index.js
Last active April 20, 2017 19:48
Get calendar days
import dateFns from 'date-fns';
function getMonthDays(date) {
const startOfMonth = dateFns.startOfMonth(date);
const endOfMonth = dateFns.endOfMonth(date);
let prevMonthDaysNeeded = startOfMonth.getDay();
const prevMonthDays = prevMonthDaysNeeded ? dateFns.eachDay(
dateFns.subDays(startOfMonth, prevMonthDaysNeeded),
dateFns.subDays(startOfMonth, 1)

Keybase proof

I hereby claim:

  • I am techniq on github.
  • I am techniq (https://keybase.io/techniq) on keybase.
  • I have a public key whose fingerprint is 4128 E489 262F 14C2 6C06 43DE EDE7 A77D 2F9B 9ABD

To claim this, I am signing this object:

@techniq
techniq / remoting.ps1
Last active June 28, 2016 23:37
PowerShell remoting
Enable-PSRemoting
$creds = Get-Credential
Enter-PSSession -ComputerName [NAME] -Credentials $creds
Invoke-Command -ComputerName [NAME] -Credentials $creds { get-UICulture }
http://www.thecodeking.co.uk/2011/02/winrm-with-mixed-domain-environments.html
http://technet.microsoft.com/en-us/library/hh849707.aspx
@techniq
techniq / README.md
Last active February 18, 2016 16:07
Element prototype oddity in Chrome console

Element prototype oddity in Chrome console

Object.getPrototypeOf(document.createElementNS('html', 'div'))
  1. When I run this from a script on Chrome 48 (stable) or 50 (canary) I get the expected/desired HTMLDivElement (codepen)
  2. When I run this within the console on Chrome 48 I get Element (no HTMLDivElement or HTMLElement)
  3. When I run this within the console on Chrome 50 I get Node (no HTMLDivElement, HTMLElement, or Element)