Skip to content

Instantly share code, notes, and snippets.

View jgdev's full-sized avatar
🏠
Working from home

Joan Peralta jgdev

🏠
Working from home
View GitHub Profile
@jgdev
jgdev / index.html
Last active June 1, 2022 19:04
Get percentage of image loading.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Get percentage loaded from image</title>
<script type="text/javascript">
Image.prototype.onChangeSize;
Image.prototype.load = function(url){
var _this = this,
req = ((XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
@jgdev
jgdev / startsWith_endsWith.js
Last active August 29, 2015 14:01
Google Chrome and Opera Pollyfills [startsWith, endsWith]
if(!String.startsWith) {
String.prototype.startsWith = function startsWith(start) {
var index = start.length;
var subStr = this.substr(0, index);
return subStr === start;
};
}
if(!String.endsWith) {
String.prototype.endsWith = function endsWith(end) {
@jgdev
jgdev / loadingColor.js
Created June 24, 2014 20:11
Loading color output
var Jetty = require('jetty'),
cls = require('cli-color'),
jetty = new Jetty(process.stdout);
jetty.clear();
var console_color = [
{range: 0, limit: 9, color: 196},
{range: 10, limit: 19, color: 202},
{range: 20, limit: 29, color: 214},
@jgdev
jgdev / memorysizeof.js
Created December 2, 2014 20:58
Memory size of an object
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if (obj !== null && obj !== undefined) {
switch (typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
@jgdev
jgdev / singleton.js
Created August 8, 2015 05:54
Singleton Design Pattern with RequireJS
define(
[],
function () {
var instance;
var Class = function () {};
return function getInstance() {
if(!instance) {
instance = new Class();
@jgdev
jgdev / pre-commit
Created January 10, 2017 16:34
Git hook jshint
#!/bin/sh
server_pass=true
client_pass=true
echo "\nValidating JavaScript:\n"
SERVER_FILES=$(jshint --config ./config/.jshintrc-server --exclude node_modules,public,client,bower_components .)
CLIENT_FILES=$(jshint --config ./config/.jshintrc-client client)
#include <iostream>
using namespace std;
class Stack
{
public:
Stack(int);
~Stack();
#include <iostream>
using namespace std;
template <typename T, int N>
int binarySearch(T(&array)[N], int toSearch) {
int start = 0;
int length = N - 1;
while (start <= length) {
@jgdev
jgdev / HashMap.cpp
Created August 31, 2017 00:35
HashMap.cpp
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
const int TABLE_SIZE = 128;
class HashEntry
{
public:
@jgdev
jgdev / validate-document-id.js
Created September 18, 2017 14:54
Function to validate identity document - Dominican Republic - Javascript
function isValidDocument(document) {
if (!document) return false;
if (document.includes('-')) {
document = document.replace(/-/g, '');
}
let verificador = 0;
let digito = 0;
let digitoVerificador = 0;
let digitoImpar = 0;
let sumaPar = 0;