Skip to content

Instantly share code, notes, and snippets.

View crshmk's full-sized avatar

Chris Hammock crshmk

  • Nha Trang, Vietnam
View GitHub Profile
@crshmk
crshmk / App.js
Last active December 3, 2018 22:34
nested react router 4
let data = {
one: {links: ['one', 'two','three'], stuff: {one: 1, two: 2, three: 3} },
two: {links: ['four', 'five','six'], stuff: {four: 4, five: 5, six: 6} },
three: {links: ['seven', 'eight','nine'], stuff: {seven: 7, eight: 8, nine: 9} }
}
class App extends Component {
constructor(props) {
super(props)
}
@crshmk
crshmk / snippets.cson
Last active March 10, 2019 19:28
Atom snippets
'.source.js':
'React Component':
'prefix': 'rc'
'body': """
import React, { Component } from 'react'
export default class ${1:Classname} extends Component {
constructor(props) {
super(props)
let util = require('util')
export default function inspect(x, depth) {
console.log(util.inspect(x, {showHidden: true, depth: depth || null}))
}
@crshmk
crshmk / sandbox.html
Last active October 25, 2020 05:12
React Sandbox
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Sandbox</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
</head>
<body>
@crshmk
crshmk / getQueryParams.js
Last active June 12, 2020 23:20
ramda pipelines to get or set query params
// takes the window
// returns params as an object
export const getQueryParams = pipe(
path(['location', 'search']),
tail,
split('&'),
map(split('=')),
fromPairs,
map(decodeURI)
);
@crshmk
crshmk / replaceItem.js
Last active October 23, 2020 19:38
updating a collection
import { always, map, propEq, when } from 'ramda'
let replaceItem = (item, list) =>
map(when( propEq('id', item.id) , always(item)), list)
export default replaceItem
@crshmk
crshmk / getFirstAndLastInitials.js
Last active October 25, 2020 16:31
grab initials from a name
import {
concat,
head,
last,
map,
pipe,
split
} from 'ramda';
let getNames = split(' ');
@crshmk
crshmk / fetchWithHooks.html
Last active November 12, 2020 19:31
fetching with hooks
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Sandbox</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
</head>
<body>
@crshmk
crshmk / file.test.js
Created November 13, 2020 22:58
mock lodash.debounce
jest.mock('lodash.debounce', () => jest.fn(fn => fn))
@crshmk
crshmk / useAuth.html
Last active November 25, 2020 16:58
global user / auth hook
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>useAuth hook</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
</head>
<body>