Skip to content

Instantly share code, notes, and snippets.

View sandroweb's full-sized avatar
🧑‍💻

Sandro Santos sandroweb

🧑‍💻
View GitHub Profile
@sandroweb
sandroweb / useLocalStorage
Last active January 11, 2024 22:57
A React Hook to manage LocalStorage items with generic type, with set, refresh and remove actions.
import { useCallback, useMemo, useState } from 'react';
export interface useLocalStorageProps<T> {
id: string;
defaultValue: T;
}
export interface useLocalStorageReturn<T> {
setValue: (value: T) => void;
value: T;
@sandroweb
sandroweb / facebook-public-feed
Created July 7, 2017 16:33
Sample code to load feed of Facebook Public Page or Public Group
$.ajax({url:"https://graph.facebook.com/{PAGE-ID}/feed?access_token={APP-ID}|{APP-SECRET}&fields=picture,full_picture,message,created_time", success: function (r) {
var html = "",
item;
console.log(r);
for (var i = 0; i < r.data.length; i++) {
item = r.data[i];
html = html + '<div class="item">';
if (item.picture) {
html = html + '<img src="' + item.full_picture + '">';
function animateVerticalScroll(px, scope, callback, options) {
var time,
callbackCalled = false,
obj;
options = options || {};
options.time = options.time || 1000;
currScroll = scope.scrollTop();
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return email.match(re);
}
function isSequentialNumber(code, reversed) {
var codeArr = code.split(''),
i,
total = codeArr.length;
if (reversed) {
codeArr = codeArr.reverse();
}
for (i = 0; i < total - 1; i = i + 1) {
if (Number(codeArr[i + 1]) !== Number(codeArr[i]) + 1) {
return false;
function addMinDecimal(n, minDecimal) {
var numberArr = String(n).split(''),
i,
total = minDecimal - numberArr.length,
zeros = '';
if (total > 0) {
for (i = 0; i < total; i = i + 1) {
zeros = zeros + '0';
}
}