Skip to content

Instantly share code, notes, and snippets.

@scottmas
scottmas / side-effects.tsx
Last active December 5, 2019 02:05
Side effects in render
function superExpensiveMapFn(num) {
//do something synchronous and very expensive, compounded by the fact that the array it operates on is very large
return num;
}
function useExpensiveDerivation(largePushOnlyArray: number[]){
const prevPushOnlyArray = useRef(largePushOnlyArray);
const derivedArray = useRef(useMemo(() => largePushOnlyArray.map(superExpensiveMapFn), []))
@scottmas
scottmas / generate-react-component-from-svg.js
Created February 26, 2019 16:11
Hack to support vector-effect: non-scaling-stroke
/****
*
* A super clunky svg file to react component converter very similar in spirit to the somewhat popular svgr library (https://www.npmjs.com/package/svgr/v/1.4.0)
* But we have the additional requirement of needing to scale the svg while __preserving__ the stroke width. And unfortunately
* react-native-svg does not support the only config value that would enable this. Namely, the property `vector-effect="non-scaling-stroke"`.
* Follow the issue here: https://github.com/react-native-community/react-native-svg/issues/885
* Eventually, once the issue is resolved, we should move to svgr and simply use the svg `scale` property
*/
const path = require("path");
@scottmas
scottmas / gist:daed992544354a4bf737
Created May 6, 2015 05:46
String replace but ignore quoted section
//Exactly like String.replace except it ignores matches inside of single or double quotes
function replaceIgnoreQuoted(string, find, replaceOrCb) {
var quotedString = /(["'])(?:\\?.)*?\1/g;
var indexOfStrings = [],
match;
quotedString.lastIndex = 0;
while(match = quotedString.exec(string)) {
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script>
<![endif]-->
<title>MeekroDB -- The Simple PHP MySQL Library</title>
@scottmas
scottmas / ngTap.js
Created December 18, 2013 20:01 — forked from mhuneke/ngTap.js
app.directive("ngTap", ["$parse", function($parse) {
return function($scope, $element, $attributes) {
var tapped;
tapped = false;
$element.bind("click", function(event) {
if (!tapped) {
var fn = $parse($attributes["ngTap"]);
$scope.$apply(function() {
fn($scope, {$event:event});
});
@scottmas
scottmas / expand-float
Created December 11, 2013 20:27
Float expand. Forces element to expand to bottom of floated content;
//expand-float actually isn't a mixin, but a useful class that must be given in the html
.expand-float:before,
.expand-float:after {
content: "";
display: table;
}
.expand-float:after {
clear: both;
}