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 / 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:
import * as http from "http";
import * as https from "https";
import * as HttpError from "standard-http-error";
import { URL } from "url";
export default function makeRequest(url: string, options: any = {}): any {
if (!url) {
throw new Error("Invalid url");
}
return new Promise((resolve, reject) => {
@jgdev
jgdev / get_unused_port.sh
Created December 13, 2017 19:22
Get unused port on shell
#!/bin/sh
port=-1
get_unused_port()
{
while [ "$port" -eq "-1" ]
do
p="$(jot -r 1 4444 65000)"
r=$(nc -z 127.0.0.1 $p > /dev/null 2>&1 && echo "used")