Skip to content

Instantly share code, notes, and snippets.

View busticated's full-sized avatar

Busticated busticated

View GitHub Profile
@busticated
busticated / example.test.mjs
Last active November 12, 2023 01:48
How to use ARC's / AWS' `client._doc.transactWrite()` method?
// Trying to implement field uniqueness as described in:
// https://aws.amazon.com/blogs/database/simulating-amazon-dynamodb-unique-constraints-using-transactions/
// Using:
// mocha: v10.2.0
// node: v18.18.2
// macOS: Sonoma v14.1 (23B74)
import sinon from 'sinon'; // sinon@17.0.1
@busticated
busticated / Foo.js
Created January 11, 2018 19:42
React Context + GatsbyJS
// src/components/Foo.js
import createClass from 'create-react-class';
import { div, em } from 'react-dom-factories';
import PropTypes from 'prop-types';
export default createClass({
displayName: 'Foo',
contextTypes: {
count: PropTypes.number
@busticated
busticated / codemod-react-proptypes.js
Last active February 9, 2022 11:54
whitepace + jscodeshift
'use strict';
///////////////////////////////////////////////////////////////////////////////
// USAGE: jscodeshift ./lib/ -t ./scripts/codemod-react-proptypes.js
///////////////////////////////////////////////////////////////////////////////
module.exports = function(file, api){
var js = api.jscodeshift,
root = js(file.source),
shouldFixWhitespace,
collection;
@busticated
busticated / gist:bc5de9dbdbf2d4f2b3524cbacf725844
Created March 17, 2017 18:42
Dissecting webpack build stats...
here's an interesting snippet from my `stats.json` file as generated by webpack v2.2.1
notes:
+ for brevity, i've stripped out the actual "source": field
+ the only modules i recognize in the block copied below are:
* dom.js (/path/to/my/project/lib/client/util/dom.js - a module i wrote)
* transit.js (/path/to/my/project/node_modules/transit-js/transit.js - a dependency of a dependency)
+ both dom.js and transit.js use `Buffer` in the node.js context only (e.g. if node.js, use Buffer, else other thing)
+ `"userRequest": "Buffer"` <-- does this mean webpack found a mention of the `Buffer` variable and that's why it's being included?
@busticated
busticated / viewport.html
Created January 4, 2016 19:25
viewport dimensions test harness
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="HandheldFriendly" content="True" />
<meta name="MobileOptimized" content="320" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
<style>
html,
body {
@busticated
busticated / gist:797d552bc8c47174c4e5
Created November 26, 2014 17:56
react derpery...
<html>
<head></head>
<body>
<!-- #container wraps the entire page's markup (except on-demand stuff like modals) -->
<!-- #container's children and classnames change based on the current view / route -->
<div id="#container" class="VIEW VIEW--MODE">
<nav></nav>
<header></header>
<main></main>
<footer></footer>
app.factory('fileUpload', function($q){
return {
send: function(files){
var deferred = $q.defer(),
data = new FormData(),
xhr = new XMLHttpRequest();
angular.forEach(files, function(file){
data.append('file', file, file.name);
});
@busticated
busticated / gist:5961163
Last active December 19, 2015 13:19
angularjs routes... how do they work?
app.config(function($routeProvider, $locationProvider){
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider
.when('/', {
templateUrl: '/html/home.html',
controller: 'HomeCtrl'
})
.when('/templates', {
templateUrl: '/html/tmpl.list.html',
controller: 'TmplCtrl'
@busticated
busticated / arena.js
Created March 28, 2012 03:35
AMDWTF: So you want to AMD...
define( [ 'jquery', 'mods/crazydot' ], function( $, CrazyDot ){
var dots = [];
var setup = function( cfg ){
while ( dots.length < cfg.count ){
dots.push( new CrazyDot( cfg.speed, 'body' ).move() );
}
};
var stopGame = function(){
@busticated
busticated / gist:1348409
Created November 8, 2011 17:14 — forked from jrburke/basic.js
possible jquery plugin boilerplate
(function(root, factory) {
if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Use a named plugin in case this
// file is loaded outside an AMD loader,
// but an AMD loader lives on the page.
define('myPlugin', ['jquery'], factory);
} else {