Skip to content

Instantly share code, notes, and snippets.

View jeswin's full-sized avatar

Jeswin jeswin

View GitHub Profile
@jeswin
jeswin / router-article-create-todos.js
Created February 9, 2019 08:11
router-article-create-todos
const todos = [
{ id: 1, text: "Buy Milk" },
{ id: 2, text: "Pay Bills" },
{ id: 3, text: "Write Article" },
{ id: 4, text: "Sleep Early" }
];
@jeswin
jeswin / router-article-startup.js
Last active February 9, 2019 11:00
router-article-startup
if (document.readyState === "loading") {
// Loading hasn't finished yet
document.addEventListener("DOMContentLoaded", startup);
} else {
// `DOMContentLoaded` has already fired
startup();
}
function startup() {
ReactDOM.render(
@jeswin
jeswin / router-article-home-component.js
Last active February 9, 2019 11:16
router-article-home-component
const Home = ({ pathArr }) => {
const [pathInState, setPathFn] = useState(pathArr);
storePathInState = setPathFn;
return pathInState[0] === "todos" ? (
// If the first part of the url is /todos, show the TodoList component
<TodoList todos={todos} pathArr={pathInState} />
) : pathInState[0] === "about" ? (
// If the first part of the url is /todos, show the TodoList component
<About />
@jeswin
jeswin / router-article-click-handler.js
Last active February 9, 2019 11:02
router-article-click-handler
function createClickHandler(url) {
return ev => {
history.pushState({}, undefined, url);
storePathInState(url.split("/").slice(1));
ev.preventDefault();
};
}
@jeswin
jeswin / router-article-popstate.js
Last active February 9, 2019 11:03
router-article-popstate
window.onpopstate = ev =>
storePathInState(window.location.pathname.split("/").slice(1));
@jeswin
jeswin / router-article-todos.js
Last active February 9, 2019 11:20
router-article-todos
const TodoList = ({ todos, pathArr }) => {
const [first, todoId] = pathArr;
return (
<div>
<h1>Todos Module</h1>
{typeof todoId === "undefined" ? (
<div>
<h2>List of todos:</h2>
{todos ? (
todos.map(todo => <Todo key={todo.id} todo={todo} />)
@jeswin
jeswin / router-article.full.html
Last active January 24, 2020 13:39
router-article-full
<html>
<head>
<script
src="https://unpkg.com/react@16/umd/react.development.js"
crossorigin
></script>
<script
src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
crossorigin
></script>
@jeswin
jeswin / package-exact.js
Last active December 9, 2020 02:02 — forked from kentcdodds/package-exact.js
make your package.json dependencies be the exact version that's in your node_modules currently
/* jshint node:true */
/* eslint-env node */
/*
* This will look at the current version of all of your dependencies and update your package.json
* with the specific version that you currently have in node_modules. This will save you from the
* sadness that is: DEPENDENCY MANAGEMENT
*
* Place this file in a folder that's a a sibling to your package.json and node_modules
* Then simply run: node scripts/package-strict
@jeswin
jeswin / calicutshop-topframe.js
Created January 19, 2021 11:28
calicutshop-topframe.js
// Copyright Pristine Initiatives, 2000. No part of this may be -
// copied without written consent from Pristine Initiatives.
// Please send all bug reports, comments to jeswin@eudoramail.com
// upd : 12/27/00 m/d/y
//globals
/*
todo :
imp >> on uploading change the root to / instead of CalicutShop/ : done
*/
@jeswin
jeswin / update-npm-deps.sh
Created February 11, 2021 07:36
Update npm dependencies in package.json to latest version
basho --import './package.json' pack -j pack -j 'Object.keys(x.dependencies)' -m x -e 'npm install ${x}@latest'