Skip to content

Instantly share code, notes, and snippets.

View hemepositive's full-sized avatar

Jonathan White, MD hemepositive

  • Huntsville Hospital
  • Huntsville, AL
View GitHub Profile
@hemepositive
hemepositive / react-hooks-toggle-switch-counter-demo.js
Created January 31, 2020 23:51 — forked from djD-REK/react-hooks-toggle-switch-counter-demo.js
Use React Hooks to Create a Toggle Switch or Counter
import React, { useState } from "react";
import ReactDOM from "react-dom";
import "./styles.css";
function App() {
const [isToggled, setToggled] = useState(false);
const [counterState, setCounterState] = useState(0);
const toggleTrueFalse = () => setToggled(!isToggled);

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@hemepositive
hemepositive / LICENSE
Created April 2, 2019 18:12 — forked from ourmaninamsterdam/LICENSE
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@hemepositive
hemepositive / CarsList.js
Last active July 17, 2018 14:18 — forked from JoaoCnh/CarsList.js
Pattern: setState with callback API call and Conditional rendering
// https://hackernoon.com/do-more-with-less-using-render-props-de5bcdfbe74c
export default class CarsList extends React.Component {
state = {
cars: [],
isLoading: false,
};
_fetch = async () => {
const res = await fetch("api/url");
@hemepositive
hemepositive / appdemo.js
Created June 21, 2018 12:54 — forked from astagi/appdemo.js
Text to speech Angular Service
var app = angular.module('demo', ['textToSpeech']);
app.controller('demoCtrl', function($scope, $timeout, textToSpeech) {
textToSpeech.onVoiceReady(function(){
textToSpeech.speak(
'You worked 9 hours!!',
'UK English Male',
{pitch: 2}
).then(function() {
alert('Finish!');
}, function(err) {
class SearchStore {
@observable searchText;
@action
setSearchText = (searchText) => {
this.searchText = searchText
}
}
@observer
@hemepositive
hemepositive / event-handlers-with-parameters-property-initializer.js
Last active June 11, 2018 18:35 — forked from sanketmeghani/event-handlers-with-parameters-property-initializer.js
React event handler with parameters using property initializer syntax CURRYING
// To pass parameters to event handlers while using property initializer syntax, we need to use currying.
// https://medium.freecodecamp.org/reactjs-pass-parameters-to-event-handlers
// Currying is the process of taking a function with multiple arguments and
// turning it into a sequence of functions each with only a single argument.
//https://medium.com/front-end-hacking/javascript-es6-curry-functions-with-practical-examples
handleClick = (param) => (e) => {
console.log('Event', e);
console.log('Parameter', param);
//Look for other responsivevoice instances
/*if (window.parent != null) {
var iframes = window.parent.document.getElementsByTagName('iframe');
for (var i = 0; i < iframes.length; i++) {
//iframes[i].style.width = "300px"
}
}*/
if (typeof responsiveVoice != 'undefined') {
console.log('ResponsiveVoice already loaded');
@hemepositive
hemepositive / UncontrolledRefForm.js
Created October 26, 2017 20:50 — forked from siakaramalegos/UncontrolledRefForm.js
Basic uncontrolled inputs form using refs
import React, { Component } from 'react'
export default class UncontrolledRefsForm extends Component {
onSubmit = (e) => {
e.preventDefault()
// Usually, we would pass the final input values to a function that
// would do something with the data like persist it to a database.
// Using refs, we just need to pass the reference values.
console.log({
firstName: this.firstName.value,
@hemepositive
hemepositive / UncontrolledSerializedForm.js
Created October 26, 2017 20:49 — forked from siakaramalegos/UncontrolledSerializedForm.js
Basic uncontrolled inputs using form serialization to get data from form
import React, { Component } from 'react'
// Import the serialize function from the form-serialize package
import serialize from 'form-serialize'
export default class UncontrolledSerialized extends Component {
onSubmit = (e) => {
e.preventDefault()
// Usually, we would pass the final input values to a function that
// would do something with the data like persist it to a database.
// Using serialization, we just need to pass that function the