Skip to content

Instantly share code, notes, and snippets.

View andrit's full-sized avatar

Andrew Ritter andrit

View GitHub Profile
postData = (url = '', data = {}, fetchmethod = 'POST', fetchmode) => {
        const esc = encodeURIComponent;
        var query = Object.keys(data)
                    .map(k => esc(k)+ '=' + esc(data[k]))
                    .join('&');
        return fetch(url, {
            method: fetchmethod, // *GET, POST, PUT, DELETE, etc.
            mode: fetchmode, // no-cors, cors, *same-origin
 cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
@andrit
andrit / conditionalRenderingReactSwitch.md
Created September 17, 2018 14:06
using a switch in a custom method in react to do conditionalrender
renderSectionOnState = () =>{
     switch(this.state.activeSection){
      case 'introsection':
        return <IntroScreen 
                  handleSwitchSection={this.handleSwitchSection} 
                  activeSection={this.state.activeSection} />
      break;
      case 'basicinfosection':
 return 
updateFieldValue = e => {
        this.setState({
            [e.target.name]: e.target.value
        });
    };
If nested:
const fs = require(‘fs’).promises;
async function cat(filenmz) {
  for (var filenm of filenmz) {
    let data = await fs.readFile(filenm, ‘utf8’);
    await new Promise((resolve, reject) => {
      process.stdout.write(data, ‘utf8’, (err) => {
        if (err) reject(err);
        else resolve();
 });
@andrit
andrit / customObjectIterator.md
Last active August 11, 2018 19:48
define a custom default @@iterator for an object and access with ES6 for...of
var myObj = {
  a:2,
  b:3
}

Object.defineProperty( myObj, Symbol.iterator, {
  enumerable: false,
  writable: false,
  configurable: true,
const withAmount = currencyComponents =>
  class Amount extends Component {
    constructor(props) {
      super(props);

      this.state = {
        amount: 0,
      };
    }
git clone --depth=1 https://github.com/react-boilerplate/react-boilerplate.git myapp
cd myapp
npm run setup
npm run clean
npm install
npm i react-motion
create-react-app myapp
cd myapp/src
mkdir containers routes utils views
touch config.js contexts.js
mv App.* routes
sed -i '' -e 's/.\/App/.\/routes\/App/g' index.js
function maxChar(str) {
  const charMap = {};
  let max = 0;
  let maxChar = '';

  for (let char of str) {
    if (charMap[char]) {
 charMap[char]++;
function chunk(array, size) {
  const chunked = [];
  let index = 0;

  while (index < array.length) {
    chunked.push(array.slice(index, index + size));
    index += size;
  }