Skip to content

Instantly share code, notes, and snippets.

Petar Bojinov pbojinov

Block or report user

Report or block pbojinov

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
@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
View customPropType.isRequired.js
// Andrew Clark's explanation: https://github.com/facebook/react/issues/9125#issuecomment-285531461
// ---
// Checking for isRequired on custom validator
// PropTypes source: https://github.com/facebook/prop-types/blob/master/factoryWithTypeCheckers.js#L206-L217
// -------------------------------------------------------------------------------------------------------
// This is a factory function (also called a higher-order function)
function createCustomPropType(isRequired) {
// The factory returns a custom prop type
return function(props, propName, componentName) {
const prop = props[propName];
View snippet.html
<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
<script>
(function(f, a, t, h, o, m){
a[h]=a[h]||function(){
(a[h].q=a[h].q||[]).push(arguments)
};
o=f.createElement('script'),
m=f.getElementsByTagName('script')[0];
o.async=1; o.src=t; o.id='fathom-script';
m.parentNode.insertBefore(o,m)
You can’t perform that action at this time.