Skip to content

Instantly share code, notes, and snippets.

View pbojinov's full-sized avatar

Petar Bojinov pbojinov

View GitHub Profile
@pbojinov
pbojinov / canada_states_titlecase.json
Last active March 1, 2024 22:24 — forked from mshafrir/states_hash.json
US states & Canadian Provinces in JSON form
[
{
"name": "Alberta",
"abbreviation": "AB"
},
{
"name": "British Columbia",
"abbreviation": "BC"
},
{
@pbojinov
pbojinov / bookmarklet.js
Created October 14, 2019 18:56
Safeway Just For You - Automatic Coupon Clipper
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
@pbojinov
pbojinov / README.md
Last active December 8, 2023 21:09
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

@pbojinov
pbojinov / broadcast-channel.md
Created November 28, 2023 23:19 — forked from davestewart/broadcast-channel.md
Example of using BroadcastChannel to communicate with pages in the same domain

screenshot

@pbojinov
pbojinov / nodejs.errno.h
Created April 18, 2014 19:07
node.js errno descriptions. Useful for debugging.
/* Pulled from https://github.com/joyent/node/blob/master/deps/uv/include/uv.h */
/* Expand this list if necessary. */
#define UV_ERRNO_MAP(XX) \
XX(E2BIG, "argument list too long") \
XX(EACCES, "permission denied") \
XX(EADDRINUSE, "address already in use") \
XX(EADDRNOTAVAIL, "address not available") \
XX(EAFNOSUPPORT, "address family not supported") \
XX(EAGAIN, "resource temporarily unavailable") \
XX(EAI_ADDRFAMILY, "address family not supported") \
@pbojinov
pbojinov / autofill.css
Created November 21, 2014 21:04
Removing input background color for Chrome autocomplete
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px white inset;
}
input:-webkit-autofill:focus {
-webkit-box-shadow: /*your box-shadow*/,0 0 0 50px white inset;
-webkit-text-fill-color: #333;
}
-webkit-text-fill-color: #838B95 !important;
@pbojinov
pbojinov / convert_wav_to_mp3.sh
Created October 20, 2017 18:44
shell script to convert all wav files in the current working directory to mp3 files using ffmpeg
#!/bin/bash
FILES=*.wav
for f in $FILES
do
# echo "Processing ${f/.wav/.mp3} file..."
echo "Processing $f file..."
ffmpeg -i "$f" -codec:a libmp3lame -qscale:a 0 "${f/.wav/.mp3}"
# take action on each file. $f store current file name
# cat $f
done
@pbojinov
pbojinov / toggle-hotcorners.scpt
Created August 10, 2015 19:02
OSX Automator script to toggle hot corners on/off with some predefined defaults. Particularly useful when playing games and need to turn off hot corner actions quickly and restore to default after.
property theSavedValues : {"Application Windows", "Mission Control", "Desktop", "Notification Center"} -- for example
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.expose"
tell application "System Events"
tell window "Mission Control" of process "System Preferences"
click button "Hot Corners…"
tell sheet 1
tell group 1
@pbojinov
pbojinov / jquery.deferred.promise.js
Last active August 31, 2022 02:38
simple jQuery Deferred example
function getData() {
var deferred = $.Deferred();
$.ajax({
'url': 'http://google.com',
'success': function(data) {
deferred.resolve('yay');
},
'error': function(error) {
deferred.reject('boo');
@pbojinov
pbojinov / summary.md
Last active August 20, 2022 19:42
useReducer vs useState vs useContext – https://www.robinwieruch.de/react-usereducer-vs-usestate/

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)