Skip to content

Instantly share code, notes, and snippets.

View craigcoles's full-sized avatar
:shipit:
Shippers gonna ship

Craig Coles craigcoles

:shipit:
Shippers gonna ship
View GitHub Profile
@mmazzarolo
mmazzarolo / elevations.ts
Last active June 1, 2022 15:12
React-Native cross platform elevation definitions
/**
* React-Native cross-platform elevations.
* Based on https://ethercreative.github.io/react-native-shadow-generator/
*
* Usage:
* 1. Import "elevations" from this file
* import { elevations } from "config/elevations";
* 2. Use it. Assuming you need an elevation of 2 (based on the Android
* elevation standard), doing the following will cast the same shadow
* on both platforms:
@mmazzarolo
mmazzarolo / useAnimation.ts
Last active May 20, 2023 01:53
A basic "useAnimation" hook for React-Native animations
import { useRef } from "react";
import { Animated, Easing } from "react-native";
export const useAnimation = function(initialValue: number = 0) {
const endValue = initialValue === 0 ? 1 : 0;
const animationValueRef = useRef<Animated.Value>(new Animated.Value(initialValue));
const setup = (config: Partial<Animated.TimingAnimationConfig> = {}) =>
Animated.timing(animationValueRef.current, {
toValue: endValue,
@philhawksworth
philhawksworth / conference-mc-tips.md
Last active February 13, 2023 21:52
Conference MC-ing tips

👀📎 It looks like you're preparing to MC a conference...

🚨 GIANT DISCLAIMER: This stuff is far from authoritative. But it's what I think works for me, and what I enjoy in an MC when I'm attending a conference.


Biggest tip - enjoy yourself.

import React, { useEffect, useRef } from "react";
import {
Animated,
Dimensions,
Image,
StyleSheet,
Text,
TouchableOpacity,
} from "react-native";
import Config from "react-native-config";
@benjaminreid
benjaminreid / hook.js
Last active June 7, 2019 16:08
React Native Modal Select
// @flow
import * as React from "react";
function useSelect(
initialValue: string | number,
items: Array<{ label: string, value: string | number }>,
) {
const [value, setValue] = React.useState(initialValue);
function onChangeValue(value: string) {
@mjackson
mjackson / useStorage.js
Last active November 4, 2021 06:36
A React hook for persisting state between page refreshes (also SSR compatible)
import { useEffect, useRef } from 'react';
function getItem(storage, key) {
const value = storage.getItem(key);
if (!value) return null;
try {
return JSON.parse(value);
} catch (error) {
@zephraph
zephraph / clean_node_modules.sh
Last active June 13, 2023 13:53
A shell script to clean up all node_modules in projects that haven't been touched in a couple weeks.
#!/bin/bash
DAYS_SINCE_LAST_CHANGE=14 # If a project hasn't been touched in this long its node_modules will be deleted
SEARCH_PATH="./Git" # Update this to the path where your code is stored
TOTAL_BYTES_REMOVED=0
Mb=1000000
Kb=1000
node_modules=$(find $SEARCH_PATH -name "node_modules" -type d -prune)
@benhowdle89
benhowdle89 / app.js
Created November 1, 2016 10:51
Redirect non-HTTPS -> HTTPS in your Express app
const requireHTTPS = (req, res, next) => {
if(req.headers['x-forwarded-proto'] !== 'https' && process.env.NODE_ENV === 'production') {
var secureUrl = "https://" + req.headers['host'] + req.url
res.writeHead(301, { "Location": secureUrl })
res.end()
}
next()
}
app.use(requireHTTPS)
@daviddarnes
daviddarnes / parallax-scrolling.js
Created October 20, 2015 08:48
Parallax scrolling with JavaScript
// Parallax header content
window.onscroll = function emParallax() {
if(window.pageYOffset>1) {
document.getElementById("parallax").style["-webkit-transform"] = "translateY("+(window.pageYOffset/3)+"px)";
} else {
document.getElementById("parallax").style["-webkit-transform"] = "translateY(0px)";
}
}
// javascripts/components/foo.js
export default function() {
console.log('foo');
}