Skip to content

Instantly share code, notes, and snippets.

View Sauloxd's full-sized avatar
🍊
orange

Saulo Furuta Sauloxd

🍊
orange
View GitHub Profile
@Sauloxd
Sauloxd / README.md
Created July 25, 2017 15:21 — forked from jesstelford/README.md
Starving the Event Loop with Microtasks

Starving the Event Loop with microtasks

Sparked from this twitter conversation when talking about doing fast async rendering of declarative UIs in Preact

These examples show how it's possible to starve the main event loop with microtasks (because the microtask queue is emptied at the end of every item in the event loop queue). Note that these are contrived examples, but can be reflective of situations where Promises are incorrectly expected to yield to the event loop "because they're async".

  • setTimeout-only.js is there to form a baseline
  • chained-promises.js shows the event loop being starved when many microtasks are queued at once
  • promises-returning-promises.js shows chained .then() calls starving the event loop
@Sauloxd
Sauloxd / itemsLargerInArray.js
Created November 27, 2017 02:58
Find how many in a given array A are larger than a given K, without exploding node engine
function findLargerInAofK(A_array, K_array) {
const A = A_array.sort((a, b) => a - b)
return K_array.map(K => {
let supportArrayIndex = [0, A.length - 1]
while (true) {
let middleIndex = Math.ceil((supportArrayIndex[1] + supportArrayIndex[0]) / 2)
if (K >= A[A.length - 1]) return 0
@Sauloxd
Sauloxd / git_create_orphan.sh
Created March 20, 2019 12:26 — forked from seanbuscay/git_create_orphan.sh
Create an orphan branch in a repo.
cd repository
git checkout --orphan orphan_name
git rm -rf .
rm '.gitignore'
echo "#Title of Readme" > README.md
git add README.md
git commit -a -m "Initial Commit"
git push origin orphan_name
@Sauloxd
Sauloxd / age.js
Last active March 30, 2019 11:15
How old are you?
const getDayMonthYear = (date) => ({
day: date.getDate(),
month: date.getMonth(),
year: date.getFullYear()
});
const pastBirthday = (birthday, today) => (today.month >= birthday.month) && (today.day >= birthday.day)
const age = (birthdayString) => {
const today = getDayMonthYear(new Date());
@Sauloxd
Sauloxd / s3-deploy.travis.yml
Last active March 30, 2019 11:43
How to deploy your static asset to S3 using travis CD
language: node_js
cache:
directories:
- node_modules
script:
- npm test
- npm run build
before_deploy: pip install --user awscli
deploy:
provider: script
@Sauloxd
Sauloxd / draftJsPluginBaseStyles.tsx
Last active June 8, 2022 13:38
Styling draft-js emoji plugin
import styled, { createGlobalStyle } from 'styled-components';
export const theme = {
emoji: 'emoji',
emojiSuggestions: 'emojiSuggestions',
emojiSuggestionsEntry: 'emojiSuggestionsEntry',
emojiSuggestionsEntryFocused: 'emojiSuggestionsEntryFocused',
emojiSuggestionsEntryText: 'emojiSuggestionsEntryText',
emojiSuggestionsEntryIcon: 'emojiSuggestionsEntryIcon',
emojiSelect: 'emojiSelect',
@Sauloxd
Sauloxd / circleci.js
Created July 22, 2020 13:13
CircleCI API
const util = require('util')
const https = require('https');
const CIRCLE_CI_TOKEN = 'Add you user token here'; //https://app.circleci.com/settings/user/tokens
const log = obj => console.log(util.inspect(obj, {showHidden: false, depth: null}));
const circleCiApi = makeCircleCiApi();
'github/QultureRocks/QultureApp'
const versionControlSystem = 'github';
const orgName = 'OrganizationName'; // If it's not in an org, fix projectSlug
cosnt repoName = 'RepoName'