Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Petar Bojinov pbojinov

🏠
Working from home
View GitHub Profile
@pbojinov
pbojinov / README.md
Last active Mar 2, 2021
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/
View README.md

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 / jquery.deferred.promise.js
Last active Feb 28, 2021
simple jQuery Deferred example
View jquery.deferred.promise.js
function getData() {
var deferred = $.Deferred();
$.ajax({
'url': 'http://google.com',
'success': function(data) {
deferred.resolve('yay');
},
'error': function(error) {
deferred.reject('boo');
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 / canada_states_titlecase.json
Last active Feb 18, 2021 — forked from mshafrir/states_hash.json
US states & Canadian Provinces in JSON form
View canada_states_titlecase.json
[
{
"name": "Alberta",
"abbreviation": "AB"
},
{
"name": "British Columbia",
"abbreviation": "BC"
},
{
View gist:9732278
SOPA Emergency IP list:
Here’s how to access your favorite sites in the event of a DNS takedown
tumblr.com 174.121.194.34
wikipedia.org 208.80.152.201
# News
bbc.co.uk 212.58.241.131
aljazeera.com 198.78.201.252
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

@pbojinov
pbojinov / multipleDeferredAjax.js
Created Feb 19, 2014
Multiple Simultaneous Ajax Requests (with one callback) in jQuery
View multipleDeferredAjax.js
// http://css-tricks.com/multiple-simultaneous-ajax-requests-one-callback-jquery/?utm_source=javascriptweekly&utm_medium=email
$.when(
// Get the HTML
$.get("/feature/", function(html) {
globalStore.html = html;
}),
// Get the CSS
$.get("/assets/feature.css", function(css) {
@pbojinov
pbojinov / data-action.js
Last active Sep 4, 2020
manually bind an event listener for each value that data-action might hold - http://alexkinnee.com/2013/11/binding-js-events-using-data-action-selectors/
View data-action.js
// Using [data-action=""] selectors instead of class selectors when binding events in JavaScript
var actions = {
action1: function() {},
action2: function() {}
//....
};
$('body').on('click', '[data-action]', function() {
var action = $(this).data('action');
if (action in actions) {
@pbojinov
pbojinov / pynamodb.py
Created Jun 21, 2014
Here is how you can create a table, with indexes, using PynamoDB - http://jlafon.io/pynamodb.html
View pynamodb.py
from pynamodb.models import Model
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection
from pynamodb.attributes import UnicodeAttribute, NumberAttribute
class DaysIndex(GlobalSecondaryIndex):
"""
This class represents a global secondary index
"""
read_capacity_units = 2
View text_to_image.py
import os
from PIL import Image, ImageDraw, ImageFont
# make sure you have the fonts locally in a fonts/ directory
georgia_bold = 'fonts/georgia_bold.ttf'
georgia_bold_italic = 'fonts/georgia_bold_italic.ttf'
# W, H = (1280, 720) # image size
W, H = (720, 405) # image size
txt = 'Hello Petar this is my test image' # text to render