Skip to content

Instantly share code, notes, and snippets.

View jgcarlson's full-sized avatar
Probably drinking coffee.

Jonathan Carlson jgcarlson

Probably drinking coffee.
View GitHub Profile
@jgcarlson
jgcarlson / install-zsh-windows-git-bash.md
Created September 23, 2021 08:59 — forked from fworks/install-zsh-windows-git-bash.md
Zsh / Oh-my-zsh on Windows Git Bash
@jgcarlson
jgcarlson / cpu-intensive.js
Created November 4, 2019 20:01 — forked from sorenlouv/cpu-intensive.js
A CPU intensive operation. Use to test imitate blocking code, test WebWorkers etc.
function mySlowFunction(baseNumber) {
console.time('mySlowFunction');
let result = 0;
for (var i = Math.pow(baseNumber, 7); i >= 0; i--) {
result += Math.atan(i) * Math.tan(i);
};
console.timeEnd('mySlowFunction');
}
mySlowFunction(8); // higher number => more iterations => slower
@jgcarlson
jgcarlson / Bluebird.txt
Created March 20, 2018 16:42 — forked from odigity/Bluebird.txt
A Snapshot of my Bluebird.js Cheat Sheet.
┌──────────┐
──┤ Overview ├─────────────────────────────────────────────────────────────────
└──────────┘
$ npm install --save bluebird
const Promise = require('bluebird')
@jgcarlson
jgcarlson / restful.js
Created February 23, 2018 05:08 — forked from BinaryMuse/restful.js
Express API with Async/Await
import express from "express";
/**
* Takes a route handling function and returns a function
* that wraps it after first checking that the strings in
* `reserved` are not part of `req.body`. Used for ensuring
* create and update requests do not overwrite server-generated
* values.
*/
function checkReservedParams(routeHandler, ...reserved) {
@jgcarlson
jgcarlson / list-constraints.sql
Created January 24, 2018 00:23 — forked from PickledDragon/list-constraints.sql
Postgres list all constraints
SELECT
tc.constraint_name, tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
@jgcarlson
jgcarlson / .babelrc
Created August 27, 2017 18:51 — forked from dengjonathan/.babelrc
Webpack/ Babel/ Express Env for React
{
"plugins": ["react-hot-loader/babel"],
"ignore":[]
}
@jgcarlson
jgcarlson / flask-flash-bootstrap
Created June 10, 2017 22:17 — forked from victorkristof/flask-flash-bootstrap
Flask flash messages as Bootstrap alert.
{% with messages = get_flashed_messages(with_categories=true) %}
<!-- Categories: success (green), info (blue), warning (yellow), danger (red) -->
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<!-- <strong>Title</strong> --> {{ message }}
</div>
{% endfor %}
{% endif %}
@jgcarlson
jgcarlson / center_div.js
Created May 16, 2017 21:26 — forked from utsengar/center_div.js
Center any div on page (think google.com's search box)
// $(element).center();
jQuery.fn.center = function ()
{
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}