Skip to content

Instantly share code, notes, and snippets.

View bovidiu's full-sized avatar
🎯
Focusing

Ovidiu Bokar bovidiu

🎯
Focusing
View GitHub Profile
@bovidiu
bovidiu / memorySizeOfObject.js
Created February 16, 2021 22:21
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@bovidiu
bovidiu / country.yml
Last active August 6, 2018 10:51
Yaml file with country codes in 2 letter format, list provided by http://fifo.cc/ffa3bc6
country:
- Afghanistan: AF
- Aland Islands: AX
- Albania: AL
- Algeria: DZ
- American Samoa: AS
- Andorra: AD
- Angola: AO
- Anguilla: AI
- Antarctica: AQ

Keybase proof

I hereby claim:

  • I am bovidiu on github.
  • I am obokar (https://keybase.io/obokar) on keybase.
  • I have a public key whose fingerprint is AAF2 88FE 4E9B CB6A 38E0 3B28 99A4 9148 2480 6A87

To claim this, I am signing this object:

@bovidiu
bovidiu / a_phar.md
Created February 19, 2018 16:24
Create a PHP Phar file

Create a PHP Phar file

Run: php create-phar.php

app.phar successfully created

Start a phar file

Run: php app.phar

@bovidiu
bovidiu / in_viewport.js
Created November 9, 2017 12:41 — forked from jjmu15/in_viewport.js
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter