Skip to content

Instantly share code, notes, and snippets.

View minmaxdata's full-sized avatar
🐕

Ke McAdams minmaxdata

🐕
  • 17:52 (UTC -07:00)
View GitHub Profile
@minmaxdata
minmaxdata / arrayMethods.js
Created August 6, 2018 20:10 — forked from iHani/arrayMethods.js
Example of array methods: forEach, map, filter, some, every, indexOf, and include. (ES2015 syntax)
/*
* forEach
*/
// forEach is very simlar to for-looping arr.length
// array.forEach(callback, context)
var arr = ['apple', 'orange', 'watermelon', 10, 20, 30]
arr.forEach((value, index) => console.log(`Element's ${index} type is ${typeof value}`))
// Prints:
// Element 0 type is string
@minmaxdata
minmaxdata / hoc.js
Created August 6, 2018 20:11 — forked from iHani/hoc.js
Higher Order Component (HOC) example with React
// Higher Order Component (HOC) : A component that renders another component
// Goal: Reduce code, render hijacking, prop manipulation, abstract state
// Inspired by mead.io videos on Udemy
import React from 'react'
import reactDOM from 'react-dom'
const info = (props) => (
<div>
<h1>Hello { props.isAdmin ? 'admin' : 'guest' }</h1>
@minmaxdata
minmaxdata / Destructuring.js
Created August 6, 2018 20:11 — forked from iHani/Destructuring.js
Destructuring in ES2015 basic examples
/*
* Object Destructuring
*/
const book = {
title: 'ReWork',
author: 'Some guy',
publisher: {
name: 'Penguin'
}
}
@minmaxdata
minmaxdata / activity.py
Created August 6, 2018 20:12 — forked from iHani/activity.py
undocumented twitter activity api
# coding: utf-8
import oauth2 as oauth
import json
CONSUMER_KEY = "yT577ApRtZw51q4NPMPPOQ"
CONSUMER_SECRET = "3neq3XqN5fO3obqwZoajavGFCUrC42ZfbrLXy5sCv8"
ACCESS_KEY = ""
ACCESS_SECRET = ""
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
@minmaxdata
minmaxdata / duplicates.js
Created August 13, 2018 16:59
Count Duplicates in an array
function hasDuplicates(numbers) {
let memo = {};
let count = 0;
numbers.map(number => {
if (!memo[number]) {
memo[number] = 1;
} else {
count++;
}
@minmaxdata
minmaxdata / main.js
Created August 13, 2018 23:58
anagrams? created by minmaxdata - https://repl.it/@minmaxdata/anagrams
function anagram(first, second) {
let one = [...first];
let two = [...second];
let temp = {}
const len = one.length === two.length;
if (len) {
temp = one.reduce(function (letters, letter) {
if (letter in letters) {
letters[letter]++
@minmaxdata
minmaxdata / main.js
Created August 14, 2018 21:58
class keyword created by minmaxdata - https://repl.it/@minmaxdata/class-keyword
class Animal {
constructor(name, energy) {
this.name = name
this.energy = energy
}
eat(amount) {
console.log(`${this.name} is eating.`)
this.energy += amount
}
@minmaxdata
minmaxdata / main.js
Created August 14, 2018 21:58
class keyword created by minmaxdata - https://repl.it/@minmaxdata/class-keyword
class Animal {
constructor(name, energy) {
this.name = name
this.energy = energy
}
eat(amount) {
console.log(`${this.name} is eating.`)
this.energy += amount
}
@minmaxdata
minmaxdata / base64-image-upload.js
Created August 3, 2019 18:31 — forked from madhums/base64-image-upload.js
save base64 encoded image
/*
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674
*/
var fs = require('fs');
// string generated by canvas.toDataURL()
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0"
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO"
+ "3gAAAABJRU5ErkJggg==";
// strip off the data: url prefix to get just the base64-encoded bytes
app.get("/my-view", async (req, res) => {
res.send(render("my-view", {data: await db.getData()}))
})
function render(view, ctx = {}) {
return _.template(fs.readFileSync(`./views/${view}.html`))(ctx)
}