Skip to content

Instantly share code, notes, and snippets.

View grundmanise's full-sized avatar
🔮
It's magic

Edgar grundmanise

🔮
It's magic
View GitHub Profile
@krazov
krazov / fibonacci-eventlooped.js
Last active February 8, 2018 15:24
Some fun with `setImmediate`
function fibonacciProcessed(x) {
return new Promise(resolve => {
const calculation = function (resolveFn, n = 0, a = 0, b = 1) {
if (n > 1) {
setImmediate(() => {
calculation(resolveFn, n - 1, b, a + b);
});
}
// else
@authenticsebastian
authenticsebastian / monthsLater.js
Last active February 12, 2018 11:23
Calculating how many months have passed since given date
const monthsLater = (date, months) =>
[
(dateArg) => new Date(dateArg),
(dateObj) => dateObj.setMonth(dateObj.getMonth() + months),
(timestamp) => new Date(timestamp),
String
].reduce(
(value, fn) => fn(value),
date
);
@authenticsebastian
authenticsebastian / fizz-buzz.js
Last active February 12, 2018 11:25
Functional take on FizzBuzz
const processNumber = (data, condition, message) => data + (condition ? message : '');
const hasNoRemainder = (number, divider) => number % divider === 0;
const rule = (value, message) => (number, data) =>
processNumber(data, hasNoRemainder(number, value), message);
const rules = [
rule(3, 'Fizz'),
rule(5, 'Buzz')
@authenticsebastian
authenticsebastian / click.js
Created May 16, 2018 15:26
Click on unfolded files in Github
[].slice.call(document.querySelectorAll('.js-file-header'))
.filter((item) => item.dataset.path.indexOf('{file-name-part}') > -1 && !item.parentNode.classList.contains('Details--on'))
.map((header) => header.querySelector('.js-details-target'))
.forEach((item) => item.click())
@andrey-skl
andrey-skl / Readme.md
Last active October 9, 2019 13:42
How to compile and run react-native application from terminal

To run on ios:

  1. Install XCode (recommended) or XCode command line tools by xcode-select --install
  2. Into XCode settings, go to "Downloads" tab and download iOS 9.2 emulator
  3. Compile native app and run it on simulator via npm run ios

To run on Android:

  1. Set up Android environment
  2. Create emulator via npm run android-emulator-create
  3. Run emulator via npm run android-emulator
  4. Compile native code and run it on emulator via npm run android
@markerikson
markerikson / react-redux-perf.md
Last active July 14, 2020 16:57
React/Redux perf discussion

[10:57 PM] acemarke: so, the canonical "bad perf for React+Redux" example is a todo list of 10,000 items
[10:58 PM] Sinistral: I always thought passing an object through was just a typical JS pointer
[10:58 PM] acemarke: the trivially obvious store shape is a single array of all 10K todo objects
[10:58 PM] acemarke: with a single connected list component
[10:58 PM] Sinistral: eh, ignore me, finish
[10:59 PM] acemarke: the list's mapState retrieves the array, and the list component renders this.props.todos.map(todo => <TodoListItem todo={todo} /> )
[10:59 PM] acemarke: which works fine the first time around
[10:59 PM] acemarke: but if you edit, say, the "text" field in a single todo
[11:00 PM] acemarke: your reducer returns a new updated todo object inside of a new array reference, shallow-copied
[11:00 PM] Sinistral: You are re-drawing the enti...oh

/** @jsx React.DOM */
'use strict';
var React = require('react'),
escapeTextForBrowser = require('react/lib/escapeTextForBrowser'),
{ PropTypes } = React;
var UncontrolledContentEditable = React.createClass({
propTypes: {
component: PropTypes.func,
@chenglou
chenglou / gist:34b155691a6f58091953
Last active April 5, 2021 19:15
Better feature for React key

key is pretty much crucial for state perservation in React. As of React 0.13 it can't do the following things:

  • Clone state
<Comp key={1} /><Comp key={1} />
  • Preserve component state across different parents:
pragma solidity ^0.4.11;
// @calvin_claus' contract
// @neuling2k didn't do anything
contract CryptoLambo {
address public dev1;
address public dev2;
@StefanLage
StefanLage / Array-Equilibrium
Last active March 31, 2022 19:59
Technical Interview : Equilibrium index of an Array
int equilibrium (int A[], int n){
int sum = 0;
int solution = -1;
int leftSum = 0;
int rightSum = 0;
// Calculate the sum of all P in A
for (int i = 0; i < n; i++)
sum += A[i];
// Try to find an equilibrium -> if yes return the first one
for (int i = 0; i < n; i++){