Skip to content

Instantly share code, notes, and snippets.

@davidfowl
davidfowl / FromSqlInterpolatedStringHandler.cs
Last active July 3, 2023 12:55
Implementation of parameterized sql queries using string interpolation handlers
using System.Data.Common;
using System.Runtime.CompilerServices;
using System.Text;
using Npgsql;
GetCatalogItemsSql(null, null, null, 10);
void GetCatalogItemsSql(int? catalogBrandId, int? before, int? after, int pageSize)
{
// This looks like it would be susceptible to SQL injection, but it's not.
@WebReflection
WebReflection / Object.getOwnPropertyDescriptors.js
Created March 3, 2014 01:39
A plural ES5 + ES6 friendly version of Object.getOwnPropertyDescriptor
'getOwnPropertyDescriptors' in Object || (
Object.getOwnPropertyDescriptors = function (Object) {
var
gOPD = Object.getOwnPropertyDescriptor,
gOPN = Object.getOwnPropertyNames,
gOPS = Object.getOwnPropertySymbols,
gNS = gOPS ? function (object) {
return gOPN(object).concat(gOPS(object));
} :
gOPN,
@B-Con
B-Con / Credit Card Generator
Last active September 24, 2022 13:02
This JavaScript function generates random number strings that pass the Luhn checksum, the test that credit card numbers must conform to. It assumes there is an HTML radio input to indicate which company issued the card. This code is from my webpage here: http://bradconte.com/cc_generator.html.
// Copyright (c) 2015, Brad Conte (http://bradconte.com)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
@nzakas
nzakas / type-declarations.js
Created December 14, 2012 22:27
Experiment: Simple way to define types, including prototypal inheritance, in JavaScript
/*
* This is just an experiment. Don't read too much into the fact that these are global variables.
* The basic idea is to combine the two steps of defining a constructor and modifying a prototype
* into just one function call that looks more like traditional classes and other OO languages.
*/
// Utility function
function mixin(receiver, supplier) {
if (Object.getOwnPropertyDescriptor) {
@kflorence
kflorence / scrollbarWidth.js
Created July 10, 2012 22:13
Calculate scroll bar width cross-browser
function getScrollBarWidth() {
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px";
var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
@nzakas
nzakas / es6proxy.htm
Created September 8, 2011 01:02
Example of ES6 Proxy
<!DOCTYPE html>
<!--
This is a simple experiment relying on ECMAScript 6 Proxies. To try this out,
use Aurora (http://www.mozilla.org/en-US/firefox/channel/).
The goal was to create a HTML writer where the method names were really just
the HTML tags names, but without manually creating each method. This uses
a Proxy to create a shell to an underlying writer object that checks each
method name to see if it's in a list of known tags.