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 / 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 / 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 / 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 / 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>
let util = require('util')
export default function inspect(x, depth) {
console.log(util.inspect(x, {showHidden: true, depth: depth || null}))
}
@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)
@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 / async.js
Last active November 21, 2018 19:13
redux async structures
function fetcher(url) {
return fetch(url).then(res => res.json())
}
async function get(url) {
var result = await fetcher(url);
return result
}
get('https://jsonplaceholder.typicode.com/users')
@crshmk
crshmk / update_node.sh
Created November 11, 2018 18:13
update node
# https://github.com/creationix/nvm
nvm install node --reinstall-packages-from=node
nvm ls
nvm alias default ${newVersion}
nvm uninstall ${oldVersion}
@crshmk
crshmk / test.spec.js
Last active October 7, 2018 05:05
vue-test-utils mounting functions
import { m, sm, mountWithPlugin } from './utils.js'
// reduce mounting boilerplate
import Component from '@/views/Comp.vue'
const wrapper = m(Component)