Skip to content

Instantly share code, notes, and snippets.

View bennadel's full-sized avatar
💭
Life's a garden, dig it!

Ben Nadel bennadel

💭
Life's a garden, dig it!
View GitHub Profile
@bennadel
bennadel / app.component.ts
Created May 1, 2018 12:42
Creating A Medium-Inspired Text Selection Directive In Angular 5.2.10
// Import the core angular services.
import { Component } from "@angular/core";
// Import the application components and services.
import { TextSelectEvent } from "./text-select.directive";
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
interface SelectionRectangle {
@bennadel
bennadel / simple-cache.js
Created March 10, 2015 11:51
Using Method Chaining With The Revealing Module Pattern In JavaScript
// Create an instance of our cache and set some keys. Notice that the [new] operator
// is optional since the SimpleCache (and revealing module pattern) doesn't use
// prototypical inheritance. And, we can use method-chaining to set the cache keys.
var cache = SimpleCache()
.set( "foo", "Bar" )
.set( "hello", "world" )
.set( "beep", "boop" )
;
console.log( cache.has( "beep" ) );
@bennadel
bennadel / Application.cfc
Created February 5, 2022 13:46
Normalizing 0xA0 (No-Break Space) And Other Special Characters Within ColdFusion Form Posts
component {
/**
* I get called once at the start of each incoming ColdFusion request.
*/
public void function onRequestStart() {
for ( var key in form ) {
if ( isSimpleValue( form[ key ] ) ) {
@bennadel
bennadel / app.component.ts
Last active March 26, 2024 14:46
Prevent Routing To Secondary View If Page Refresh In Angular 5.0.0
// Import the core angular services.
import { Component } from "@angular/core";
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
@Component({
selector: "my-app",
styleUrls: [ "./app.component.less" ],
template:
@bennadel
bennadel / .dockerignore-web
Last active March 23, 2024 16:24
From Noob To Docker On DigitalOcean With Nginx, Node.js, DataDog Logs, DogStatsD, And LetsEncrypt SSL Certificates
.*
Dockerfile
node_modules
@bennadel
bennadel / index.htm
Created August 18, 2022 12:13
Rendering Wrapped Text To A Canvas In JavaScript
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>
Rendering Wrapped Text To A Canvas In JavaScript
</title>
<link rel="stylesheet" type="text/css" href="./main.css" />
</head>
<body>
@bennadel
bennadel / map.ts
Created June 7, 2017 12:10
Using Type Argument Inference When Accepting Generic Callbacks In TypeScript And Node.js
// I define the callback function interface for the .map() method. This entire interface
// is parameterized with the given Type <T> so that we can facilitate "type argument
// inference" in the method signature for .map().
interface TokensMapCallback<T> {
( token: string ) : T;
}
class Tokens {
private _tokens: string[];
@bennadel
bennadel / schema_auto_increment_columns.sql
Created December 20, 2020 13:53
Looking For Database Performance Bottlenecks And Optimizations Using The Sys Schema In MySQL 5.7
/**
* Find the amount of auto-increment "space" has been used. This may can help identify
* tables that are running out of available ID values.
*/
SELECT
t.table_name,
t.column_name,
-- The highest possible ID that can be created with this data-type.
t.max_value,
-- The last ID created in this table.
@bennadel
bennadel / api-client.ts
Created May 7, 2018 12:58
Proof Of Concept: Using Axios As Your HTTP Client In Angular 6.0.0
import axios from "axios";
import { AxiosInstance } from "axios";
import { ErrorHandler } from "@angular/core";
import { Injectable } from "@angular/core";
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
export interface Params {
[ key: string ]: any;
@bennadel
bennadel / group-by-ip.sql
Created March 21, 2016 23:27
Grouping The MySQL PROCESSLIST By IP Address To View Connection Counts
SELECT
tmp.ipAddress,
-- Calculate how many connections are being held by this IP address.
COUNT( * ) AS ipAddressCount,
-- For each connection, the TIME column represent how many SECONDS it has been in
-- its current state. Running some aggregates will give us a fuzzy picture of what
-- the connections from this IP address is doing.
FLOOR( AVG( tmp.time ) ) AS timeAVG,