Skip to content

Instantly share code, notes, and snippets.

Daniel Schmidt thebuilder

Block or report user

Report or block thebuilder

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@thebuilder
thebuilder / Button.jsx
Created Mar 31, 2016
Stateless Button with basic onClick event
View Button.jsx
import React from 'react';
function handleClick(event) {
alert('click ' + event);
}
function Button({label}) {
return (
<button onClick={handleClick}>{label}</button>
);
@thebuilder
thebuilder / Button-arrow-func.jsx
Last active Apr 5, 2016
Stateless Button with arrow binding - But this creates a new instance on every render?
View Button-arrow-func.jsx
import React from 'react';
function handleClick(label) {
alert('clicked ' + label);
}
function Button({label}) {
return (
<button onClick={(event) => handleClick(label)}>{label}</button>
@thebuilder
thebuilder / gist:5081990
Last active Jun 27, 2016
Get the root FrameLayout of an Android activity.
View gist:5081990
public FrameLayout getRootFramelayout() {
if (_root == null) _root = (FrameLayout) getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
return (FrameLayout) _root.getChildAt(0);
}
@thebuilder
thebuilder / frameLoop.js
Created Sep 8, 2015
Call a function with a specific FPS. Exposes methods to pause, start and destroy the looper. Uses ES6.
View frameLoop.js
/**
* @param fn {Function} Callback function to trigger on frame
* @param fps {int} Target FPS
* @returns {{pause: pause, start: start, destroy: destroy}}
*/
function frameLoop(fn, fps=60) {
let then = 0;
let interval = 1000 / fps;
let isRunning = true;
let currentFrameId = null;
@thebuilder
thebuilder / Example.story.js
Last active Dec 15, 2017
Mock Fetch requests in Storybook
View Example.story.js
import React from 'react'
import { storiesOf } from '@storybook/react'
import FetchStory from './FetchStory'
storiesOf('Fetch Example', module)
.add('Plain', () => (
<FetchStory mocks={{
matcher: '/api/signup',
response: {
body: {
@thebuilder
thebuilder / jest.config.js
Last active Jun 8, 2018
Use Jest Projects to run both JSDom and Node tests in the same project
View jest.config.js
module.exports = {
projects: [
{
displayName: 'dom',
testEnvironment: 'jsdom',
snapshotSerializers: ['enzyme-to-json/serializer'],
testMatch: ['**/__tests__/**/*.test.js?(x)']
},
{
displayName: 'node',
@thebuilder
thebuilder / gist:7248688
Created Oct 31, 2013
Events with correct scope in TypeScript
View gist:7248688
class Tracker {
count = 0;
constructor() {
window.addEventListener("mousedown", this.mouseDown);
window.addEventListener("mouseup", this.mouseUp);
}
mouseDown = (ev: MouseEvent) => {
window.addEventListener("mousemove", this.mouseMove);
}
mouseUp = (ev: MouseEvent) => {
View useInView.tsx
import * as React from 'react'
import { observe, unobserve } from './intersection'
import { HookResponse, IntersectionOptions } from './typings/types'
type State = {
inView: boolean
entry?: IntersectionObserverEntry
}
export function useInView(options: IntersectionOptions = {}): HookResponse {
@thebuilder
thebuilder / hookWithRef.js
Last active Feb 11, 2019
Hook with ref callback
View hookWithRef.js
import React, {useState} from 'react'
function useHookWithRefCallback() {
const [node, setRef] = useState(null)
useEffect(
() => {
if (node) {
// Your Hook now has a reference to the ref element.
}
You can’t perform that action at this time.