Skip to content

Instantly share code, notes, and snippets.

View misterdev's full-sized avatar
🎧

Devid Farinelli misterdev

🎧
View GitHub Profile
@axemclion
axemclion / JSIObject.cpp
Last active October 4, 2023 19:36
React Native JSI Example
// This sample is a Work in Progress for JSI , and specific functions may change.
#pragma once
#include <string>
#include <unordered_map>
#include <jsi/jsi.h>
// This SameplJSIObject needs to inheric from HostObject, and this is the object that will be exposed to JS.
@mavame
mavame / GoogleMapsApi.js
Last active December 6, 2023 21:53
A simple class for loading the Google Maps Javascript API in browser async using ES6 and Promise
/**
* Use this class to ensure Google Maps API javascript is loaded before running any google map specific code.
*/
export class GoogleMapsApi {
/**
* Constructor set up config.
*/
constructor() {
// api key for google maps
@oliyh
oliyh / image-url-to-data-uri.js
Created November 7, 2015 22:17
Convert an image url to a data URI without canvas
// hard won knowledge from http://stackoverflow.com/questions/20035615/using-raw-image-data-from-ajax-request-for-data-uri
var xmlHTTP = xhr.XMLHttpRequest();
xmlHTTP.open('GET', url, true);
xmlHTTP.responseType = 'arraybuffer';
xmlHTTP.onload = function(e) {
var arr = new Uint8Array(this.response);
var raw = String.fromCharCode.apply(null,arr);
var b64 = base64.encode(raw);
var dataURL="data:image/png;base64," + b64;
};
@paulirish
paulirish / what-forces-layout.md
Last active May 6, 2024 07:54
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@demisx
demisx / angularjs-providers-explained.md
Last active March 17, 2024 11:09
AngularJS Providers: Constant/Value/Service/Factory/Decorator/Provider
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

@katowulf
katowulf / 1_query_timestamp.js
Last active September 21, 2023 20:28
Get only new items from Firebase
// assumes you add a timestamp field to each record (see Firebase.ServerValue.TIMESTAMP)
// pros: fast and done server-side (less bandwidth, faster response), simple
// cons: a few bytes on each record for the timestamp
var ref = new Firebase(...);
ref.orderByChild('timestamp').startAt(Date.now()).on('child_added', function(snapshot) {
console.log('new record', snap.key());
});
@kekscom
kekscom / gist:5053306
Last active May 26, 2022 08:03
JavaScript toLocalISOString() function
function toLocalISOString(d) {
var off = d.getTimezoneOffset();
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes() - off, d.getSeconds(), d.getMilliseconds()).toISOString();
}
@ryasmi
ryasmi / triangular.js
Last active February 18, 2019 12:46
The function triangular returns the triangular number of the inputted value. For example triangular(3) would return 6 because 1 + 2 + 3 is equal to 6. This function accounts for both negative values and zero.
var triangular = function (value) {
var abs = Math.abs(value);
return ((abs / 2) * (abs + 1)) * (abs / value) || 0;
};
// Testing code.
var testTriangular = function () {
var testTriangularValue = function (arg, value, id) {
console.log(triangular(arg) === value ? "Test " + id + " passed." : "Test " + id + " failed.");
};