Skip to content

Instantly share code, notes, and snippets.

View yosevu's full-sized avatar

Yosevu Kilonzo yosevu

View GitHub Profile
/**
* Makes ideal change based on the difference between the purchase price of an item,
* how much cash is tendered, and the current contents of the register
*
*/
const makeChange = (purchasePrice, cashTendered, cashRegisterContents) => {
// Exact change tendered
// Oops
throw 'Insufficient Funds';
@egonSchiele
egonSchiele / why.markdown
Last active July 20, 2018 01:40
Why read Grokking Algorithms?

If you have already taken a course in algorithms, why read Grokking Algorithms (manning.com/bhargava)?

If you were learning graph algorithms, which approach would you prefer:

  1. Imagine you have to take public transit from your home to your office. How do you figure out the fastest route? Use graph algorithms! OR

  2. We can choose between two standard ways to represent a graph G = (V, E): as a collection of adjacency lists or as an adjacency matrix. Either way applies to both directed and undirected graphs.

I prefer the first way: lead with lots of examples, and clear writing. The second way is an excerpt from "Introduction to Algorithms"...that's how they start their section on graph algorithms.

@rheajt
rheajt / readme.md
Last active June 20, 2019 18:13
sass setup for create-react-app cli tool

Create-React-App with Sass configuration

Here are instructions for add Sass support to an app built with create-react-app. Hopefully this will be redundant when Sass support is built into the tool! Visit their form and let them know you need Sass support.

Install the create-react-app tool from npm. This will be installed globally. We also need to install the loaders needed for webpack, and we will save those as development dependencies.

npm install -g create-react-app

create-react-app your-app-name
cd your-app-name
@GoesToEleven
GoesToEleven / innerhtml
Created July 19, 2015 20:43
javascript innerHTML vs textContent
nodeValue is a little more confusing to use, but faster than innerHTML.
innerHTML parses content as HTML and takes longer.
textContent uses straight text, does not parse HTML, and is faster.
innerText is IE specific and also takes styles into consideration. It won't get hidden text for instance.
http://stackoverflow.com/questions/21311299/nodevalue-vs-innerhtml-and-textcontent-how-to-choose
@markerikson
markerikson / react-controlled-inputs.md
Last active June 15, 2021 12:50
React "controlled" vs "uncontrolled" inputs explanation

[12:03 AM] acemarke: "controlled" and "uncontrolled" inputs
[12:04 AM] acemarke: if I have a plain, normal HTML page, and I put <input id="myTextbox" type="text" /> in my page(edited)
[12:04 AM] acemarke: and I start typing into that textbox
[12:04 AM] acemarke: it remembers what I've typed. The browser stores the current value for that input
[12:05 AM] acemarke: and then sometime later, I can get the actual element, say, const input = document.getElementById("myTextbox"), and I can ask it for its value: const currentText = input.value;
[12:05 AM] acemarke: good so far?
[12:08 AM] acemarke: I'll keep going, and let me know if you have questions
[12:08 AM] lozio: ok, actually I'm reading
[12:09 AM] lozio: good
[12:09 AM] acemarke: so, a normal HTML input field effectively stores its own value at all times, and you can get the element and ask for its value

// tagging strings
const language = 'de'
const user = {
name: 'Kent C. Dodds',
birthday: new Date(1988, 9, 18)
}
const translated = translate`
<div>
${'t.hello'} ${user.name}, ${'t.yourBirthdayIs'} ${user.birthday}
</div>
@elnygren
elnygren / expression_problem.clj
Last active December 3, 2022 16:33
Solving the Expression Problem with Clojure
; The Expression Problem and my sources:
; http://stackoverflow.com/questions/3596366/what-is-the-expression-problem
; http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/
; http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/
; http://www.ibm.com/developerworks/library/j-clojure-protocols/
; To begin demonstrating the problem, we first need some
; "legacy code" with datastructures and functionality:
@zenorocha
zenorocha / basic.md
Last active March 26, 2023 09:00
New Firebase Auth vs Old Firebase Auth
@bendc
bendc / nodelist-iteration.js
Created January 13, 2015 14:39
ES6: Iterating over a NodeList
var elements = document.querySelectorAll("div"),
callback = (el) => { console.log(el); };
// Spread operator
[...elements].forEach(callback);
// Array.from()
Array.from(elements).forEach(callback);
// for...of statement
@dherman
dherman / emacs-cheat-sheet.md
Created August 2, 2012 16:22
My emacs cheat sheet

In penance for cracking stupid jokes on Twitter, here's my Emacs cheat sheet. Emacs has a steep learning curve, so I've tried to order them by importance so you could learn them in stages.

One overall rule of thumb: pay attention to the minibuffer (the line at the bottom of the editor). It will often guide you through a process, and also gives you hints about what state you're in, such as the middle of a multi-chord sequence.

The other rule of thumb: when in doubt, C-g it out.

Basics (mandatory)

You simply can't get by without having these at your fingertips.