Skip to content

Instantly share code, notes, and snippets.

View oscarr-reyes's full-sized avatar

Oscar Reyes oscarr-reyes

  • Colombia Medellin
View GitHub Profile
@oscarr-reyes
oscarr-reyes / ProtectedRoute.js
Created March 11, 2019 15:48
Flow throws error for rendering Component passed from a prop
// @flow
import React, { Component } from "react";
import { Redirect, Route } from "react-router-dom";
import CookieStorage from "./../services/CookieStorage";
import type { Component as ComponentType } from "react";
type Props = {
component: ComponentType<any, any>
}
@oscarr-reyes
oscarr-reyes / file.js
Last active September 25, 2018 04:14
Get stats for all directories in a path
const fs = require("fs");
const path = require("path");
const pathDir = "C:/Users/Oscar/Downloads";
const dirs = fs.readdirSync(pathDir);
dirs.forEach(async dir => {
const stats = await readStats(path.resolve(pathDir, dir));
@oscarr-reyes
oscarr-reyes / linkService.js
Created January 19, 2018 02:02
Link preview service for Angular.js
app.factory("$Link", function($q, $http){
var LINKREGEX = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+ = &%@!\-\/]))?/g;
var YOUTUBEREGEX = /(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'<> #]+)/;
var IMAGEREGEX = /(.+\w+\.(png|jpg|jpeg|ico|svg)$)/;
var SERVICE = "https://api.linkpreview.net";
var KEY = "<api-key>";
var $Link = {};
/**
* Verifies if the provided text contains a link
var data = {
"id": "3",
"create_at": "2016-10-15 05:28:10",
"account": {
"username": "mgrantbt"
},
"ticket": {
"status_id": "2"
},
"amount": {
var diet = require("diet");
var app = diet();
app.listen(8000);
require("./index.js")(app);
-- MySQL dump 10.13 Distrib 5.6.31, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: tree
-- ------------------------------------------------------
-- Server version 5.6.31-0ubuntu0.15.10.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
(function() {
'use strict';
// Pass the userService to the app
angular
.module('y')
.factory('userService', userService);
@oscarr-reyes
oscarr-reyes / accounts.factory.js
Created September 19, 2016 22:32
Factory example using ngrestful
(function() {
'use strict';
// Pass the accountsFactory to the app
angular
.module('y')
.factory('accountsFactory', accountsFactory);
// Define the accountsFactory
function accountsFactory($resource) {
@oscarr-reyes
oscarr-reyes / ng-restful.js
Last active September 11, 2016 22:01
ngRestful usage example
var app = angular.module("example", ["ngRestful"]);
// Define global domain for resource
app.config(["ngRestful", function($restful){
$restful.setDomain("http://localhost/tree/server");
}]);
app.controller("exampleController", ["$resource", function($resource){
// Domain is already defined, accounts will be appended with the domain url
var resource = new $resource("accounts");
var cy = cytoscape({
container: document.getElementById("cy"),
elements: [
// nodes
{data: {id: "a", name:"1"}},
{data: {id: "b", name:"2"}},
{data: {id: "c", name:"3"}},
{data: {id: "d", name:"4"}},
{data: {id: "e", name:"5"}},
{data: {id: "f", name:"6"}},