Skip to content

Instantly share code, notes, and snippets.

Hashem Khalifa HashemKhalifa

  • Munich, Germany
Block or report user

Report or block HashemKhalifa

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kyleshevlin
kyleshevlin / Comp.js
Created Dec 11, 2018
I don't know what to call this? render/sCU pattern of change instead of firing an action in an event handler?
View Comp.js
import React, { Component } from 'react'
class FolderFileTreeSearch extends Component {
state = {
value: '',
collapsedFolders: Set()
}
onChange = e => {
this.setState({
View string.md

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).

@ljharb
ljharb / array_iteration_thoughts.md
Last active Sep 18, 2019
Array iteration methods summarized
View array_iteration_thoughts.md

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@gaearon
gaearon / slim-redux.js
Last active Sep 19, 2019
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
View slim-redux.js
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
You can’t perform that action at this time.