Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Petar Bojinov pbojinov

🏠
Working from home
View GitHub Profile
View 20111011_SteveYeggeGooglePlatformRant.md

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real

View index.js
// Using SWR
import useSWR from 'swr'
function Profile () {
const { data, error } = useSWR('/api/user', fetcher)
if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>hello {data.name}!</div>
}
@pbojinov
pbojinov / bookmarklet.js
Created Oct 14, 2019
Safeway Just For You - Automatic Coupon Clipper
View bookmarklet.js
javascript:(function() {"use strict"; var coupons = angular.element("#lt-coupon-area").scope().sharedValues.unfilteredItems.slice(); coupons.filter(function(x){return x.clipStatus==="U";}).forEach(function(item){ var c1 = document.cookie.match(new RegExp('swyConsumerlbcookie=([^;]+)'))[1]; var c2 = document.cookie.match(new RegExp('swyConsumerDirectoryPro=([^;]+)'))[1]; var data = {"items":[]}; var clip = {}; clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;clip.vndrBannerCd=""; var list = {}; list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm; data.items.push(clip);data.items.push(list); var request = new Request('https://nimbus.safeway.com/Clipping1/services/clip/items', { method: 'POST', mode: 'cors', redirect: 'error', headers: new Headers({ 'Content-Type': 'application/json', 'X-SWY_VERSION': '1.0', 'X-SWY_API_KEY': 'emjou', 'X-SWY_BANNER': 'safeway', 'SWY_ISREMEMBERED': 'false', 'X-swyConsumerlbcookie': c1, 'X-swyConsumerDirectoryPro': c2 }), body: JSON.stringif
View summary.md

Summary

Use useState:

  1. if you manage JavaScript primitives as state
  2. if you have simple state transitions
  3. if you want to have business logic within your component
  4. if you have different properties that don’t change in any correlated manner and can be managed by multiple useState hooks
  5. if your state is co-located to your component
  6. if you’ve got a small application (but the lines are blurry here)
@pbojinov
pbojinov / memorySizeOfObject.js
Created Mar 25, 2019 — forked from zensh/memorySizeOfObject.js
calculate memory size of javascript object, it is not a accurate value!
View memorySizeOfObject.js
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
View Serverless_deploy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"cloudformation:CreateUploadBucket",
"cloudformation:CancelUpdateStack",
"cloudformation:CreateStack",
@pbojinov
pbojinov / stream_read_write.js
Last active Dec 17, 2018
streaming read from a file line by line then write to another output file
View stream_read_write.js
var fs = require('fs');
const INPUT = 'input.txt';
const OUTPUT = `output_${INPUT}`;
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream(INPUT)
});
var wstream = fs.createWriteStream(OUTPUT);
View content-body-iframe-test.js
import React from 'react';
import sinon, { spy, stub } from 'sinon';
import sinonChai from 'sinon-chai';
import { shallow, render } from 'enzyme';
import chai, { expect } from 'chai';
import chaiEnzyme from 'chai-enzyme';
import proxyquire from 'proxyquire';
chai.use(chaiEnzyme());
@pbojinov
pbojinov / webrtc-internals.txt
Last active Jul 26, 2018
UberConference - chrome://webrtc-internals/
View webrtc-internals.txt
Create Dump
Download the PeerConnection updates and stats data
Enable diagnostic audio recordings
A diagnostic audio recording is used for analyzing audio problems. It consists of several files and contains the audio played out to the speaker (output) and captured from the microphone (input). The data is saved locally. Checking this box will enable recordings of all ongoing input and output audio streams (including non-WebRTC streams) and for future audio streams. When the box is unchecked or this page is closed, all ongoing recordings will be stopped and this recording functionality disabled. Recording audio from multiple tabs is supported as well as multiple recordings from the same tab.
When enabling, select a base filename to which the following suffixes will be added:
<base filename>.<render process ID>.aec_dump.<AEC dump recording ID>
<base filename>.input.<stream recording ID>.wav