Skip to content

Instantly share code, notes, and snippets.

@mauricedb
mauricedb / Subject under test
Last active December 7, 2023 14:46
Testing stateful React hooks
import { useState } from 'react';
export function useCounter(initial = 0) {
const [count, setCount] = useState(initial);
return [count, () => setCount(count + 1)];
}
@MikeShi42
MikeShi42 / SlideTextInput.js
Created October 19, 2016 20:36
Terrible TextInput extends that doesn't steal all touches.
import React, { Component } from 'react';
import {TextInput, TouchableWithoutFeedback, StyleSheet} from 'react-native';
const Platform = require('Platform');
const requireNativeComponent = require('requireNativeComponent');
const emptyFunction = require('fbjs/lib/emptyFunction');
if (Platform.OS === 'android') {
var AndroidTextInput = requireNativeComponent('AndroidTextInput', null);
} else if (Platform.OS === 'ios') {
var RCTTextView = requireNativeComponent('RCTTextView', null);
@teameh
teameh / PanResponder_Overview.js
Last active October 21, 2023 05:28
React native PanResponder interface overview
this._panResponder = PanResponder.create({
// ----------- NEGOTIATION:
// A view can become the touch responder by implementing the correct negotiation methods.
// Should child views be prevented from becoming responder on first touch?
onStartShouldSetPanResponderCapture: (evt, gestureState) => () => {
console.info('onStartShouldSetPanResponderCapture');
return true;
},
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@ahawkins
ahawkins / deploy.rb
Created March 29, 2012 13:59
Deploy script for Heroku apps
#!/usr/bin/env ruby
# This is a basic deploy script for Heroku apps.
# It provides a structure you can use to expand on
# and add your own prereqs and deploy tasks.
#
# It basically ensures that:
# 1. There are no uncommited files
# 2. You can ssh to github
# 3. You can connect to heroku
@mojodna
mojodna / Procfile
Created September 29, 2011 20:22 — forked from RandomEtc/Procfile
Getting Kue working on Heroku
web: node app.js
worker: node consumer.js
@Stubbs
Stubbs / watchr.rb
Created March 9, 2011 18:13
This is a watchr config script that watches all the Python files in the directories specified by the "watch" command. You can specify one for each Django app in your project.
require "ruby-growl"
watch ('project/(.*).py') {|md| code_changed "#{md[0]}"}
def code_changed(file)
# Get the path of the file that changed
dir = File.dirname(file)
test(dir)
end
@jfsiii
jfsiii / img2data.js
Created January 30, 2011 23:30
base64 encoding images in NodeJS
/*
* Based on https://gist.github.com/583836 from http://stackoverflow.com/questions/3709391/node-js-base64-encode-a-downloaded-image-for-use-in-data-uri.
* Neither that gist nor this one work for me in 0.2.x or 0.3.x.
*/
var request = require('request'),
BufferList = require('bufferlist').BufferList,
sys = require('sys'),
bl = new BufferList(),
url = 'http://nodejs.org/logo.png'
;
!function() {
var doc = document,
htm = doc.documentElement,
lct = null, // last click target
nearest = function(elm, tag) {
while (elm && elm.nodeName != tag) {
elm = elm.parentNode;
}
return elm;
};