Skip to content

Instantly share code, notes, and snippets.

View ro-savage's full-sized avatar

Rowan Savage ro-savage

View GitHub Profile
@ro-savage
ro-savage / filter-list.js
Last active July 25, 2016 10:52
Methods for filtering a large array
const t0 = performance.now()
// slowest
const results = list.filter((item) => {
return matchObjPropsToValue(item, searchTerm, props, fullTextSearch)
})
Alternative method using currying an ramda.
// fast
import { matchObjPropsToValue, mapWhile } from '../helpers/match-helpers'
@ro-savage
ro-savage / UserDropDown.js
Last active May 12, 2016 01:09
Avoiding PropType warnings due to renders before API data is returned
import React from 'react'
import style from './UserDropDown.scss'
class UserDropDown extends React.Component {
render() {
const { logout, user } = this.props
return (
<div>
<span onClick={logout}>{user.username}</span>
@ro-savage
ro-savage / ScrollBehaviourContainer.js
Created June 15, 2016 23:16
Updated react-router-scroll
/* eslint-disable */
import React from 'react';
import ScrollBehavior from './scroll-behavior';
class ScrollBehaviorContainer extends React.Component {
static propTypes = {
shouldUpdateScroll: React.PropTypes.func,
routerProps: React.PropTypes.object.isRequired,
children: React.PropTypes.node.isRequired,
elTarget: React.PropTypes.string
import React from 'react'
import cloudinaryCore from 'cloudinary-core'
const cloudinary = cloudinaryCore.Cloudinary.new()
cloudinary.config({ cloud_name: 'macvad' })
// ** OPTIONS **
// height (int), width (int), crop (string - fit/scale/pad/++ - requried for resize)
// Lots more
// http://cloudinary.com/documentation/image_transformations#sample_image
@ro-savage
ro-savage / css-modules-and-globals.md
Created February 25, 2017 00:23
CSS Modules - Playing nice with regular css

There is an on going issue with using non-css module css in projects.

This causes issues with people needing to change webpack config, or mainters need to create a css-module specific version. We should not be forcing people to go through a bunch of configuration to get css modules and standard css to play nicely together.

I suggest a few ways to solve this problem long term, and I think the change should come from CSS Modules as it is non-standard.

  1. Change extension All CSS Modules have the file extension .cssm (or module.css). Then any loaders would know these are CSS modules, and other imports are standard css.
function someFunctionThatIsAsync(callback) {
/// Do something that happens asyncronously. That is, not in the order that is it called.
var data = fs.readFile('data.json')
// In this example it will execute doSomethingWithData(data)
callback(data)
}
function doSomethingWithData(data) {
document.querySelector('#data').innerText = data
// Get data from https://jsonplaceholder.typicode.com/posts
const examplePostsData = [
{
"userId": 1,
"id": 1,
"title": "Some crazy title",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
@ro-savage
ro-savage / navcoin.conf
Created July 9, 2018 12:42
Navcoin conf peers
addnode=103.247.155.206
addnode=104.251.215.107
addnode=107.184.137.78
addnode=109.81.208.33
addnode=110.169.33.99
addnode=115.189.83.40
addnode=116.197.235.221
addnode=116.50.169.42
addnode=121.148.171.122
addnode=121.44.107.8
@ro-savage
ro-savage / relayStore.js
Created February 12, 2019 10:42
Implement a cache and fetch with relay
// This code is untested. It may new some minor modifications to work
import RelayQueryResponseCache from "relay-runtime/lib/RelayQueryResponseCache";
import {
Environment,
Network,
RecordSource,
Store,
Observable