Skip to content

Instantly share code, notes, and snippets.

View thulstrup's full-sized avatar

Rasmus Thulstrup thulstrup

View GitHub Profile
@tannerlinsley
tannerlinsley / createCrudHooks.js
Created November 29, 2020 06:39
A naive, but efficient starter to generate crud hooks for React Query
export default function createCrudHooks({
baseKey,
indexFn,
singleFn,
createFn,
updateFn,
deleteFn,
}) {
const useIndex = (config) => useQuery([baseKey], indexFn, config)
const useSingle = (id, config) =>
@danielkcz
danielkcz / App.js
Created September 6, 2017 12:59
Update Expo app
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Util } from 'expo'
export default class App extends React.Component {
state = {
updated: false,
}
componentWillMount() {
Util.addNewVersionListenerExperimental(() => {

#A brief intro into Stateless functions#

So stateless functions are new in React 0.14 which are quite interesting. They look a bit like this.

const Test = ({name, amount}) => {
 return <div className="test">{name} has £{amount}</div>;
};

ReactDOM.render(<Test name="ben" amount="-2000" />) //  <div className="test">ben has £-200</div> 
@paulirish
paulirish / what-forces-layout.md
Last active April 26, 2024 17:33
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@tlrobinson
tlrobinson / redux-devtools-separate-window.js
Last active August 20, 2019 23:54
Put the awesome redux-devtools in it's own window so it doesn't obscure or be obscured by your application
// give it a name so it reuses the same window
var win = window.open(null, "redux-devtools", "menubar=no,location=no,resizable=yes,scrollbars=no,status=no");
// reload in case it's reusing the same window with the old content
win.location.reload();
// wait a little bit for it to reload, then render
setTimeout(function() {
React.render(
<DebugPanel top right bottom left >
@maximilianschmitt
maximilianschmitt / gulpfile.js
Created April 27, 2015 18:24
Using watchify with gulp
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var notifier = require('stream-notifier');
var watchify = require('watchify');
gulp.task('browserify', function() {
var bundler = browserify('./src/main')
@paulirish
paulirish / bling.js
Last active April 20, 2024 17:39
bling dot js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
@davatron5000
davatron5000 / gulp-svgstore.js
Last active May 13, 2019 05:48
Gulpin' SVGz
var cheerio = require('gulp-cheerio');
var svgmin = require('gulp-svgmin');
var svgstore = require('gulp-svgstore');
gulp.task('svgstore', function () {
return gulp
.src('assets/icons/*.svg')
.pipe(svgmin())
.pipe(svgstore({ fileName: 'icons.svg', prefix: 'icon-' }))
.pipe(cheerio({
@pburtchaell
pburtchaell / styles.css
Last active February 25, 2024 12:24
VH and VW units can cause issues on iOS devices. To overcome this, create media queries that target the width, height, and orientation of iOS devices.
/**
* VH and VW units can cause issues on iOS devices: http://caniuse.com/#feat=viewport-units
*
* To overcome this, create media queries that target the width, height, and orientation of iOS devices.
* It isn't optimal, but there is really no other way to solve the problem. In this example, I am fixing
* the height of element `.foo` —which is a full width and height cover image.
*
* iOS Resolution Quick Reference: http://www.iosres.com/
*/
@cubiq
cubiq / select-reset.html
Created May 27, 2014 12:12
How to reset a select tag
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Styled Select</title>
</head>
<style>
* {