Skip to content

Instantly share code, notes, and snippets.

View kevinfelisilda's full-sized avatar

Kevin Felisilda kevinfelisilda

View GitHub Profile
@kevinfelisilda
kevinfelisilda / GiftbitService.php
Last active August 17, 2016 04:20
Simple Giftbit Curl Library
<?php namespace App;
class GiftBit {
private $endpoint;
private $authorization;
public function init ( $endpoint, $key )
{
if ( empty($endpoint) || empty($key) )
var promise = require('promisejs');
var fs = require('fs');
function readFile(file) {
return promise(function (resolve, reject){
fs.readFile(function (err, data) {
if (err) {
reject(err);
} else {
resolve(data);
import { useEffect } from "react";
const useOutsideClick = (ref, callback) => {
const handleClick = e => {
if (ref.current && !ref.current.contains(e.target)) {
callback();
}
};
useEffect(() => {
import React, { useRef } from "react";
import useOutsideClick from "./useOutsideClick";
function MyComponent() {
const ref = useRef();
useOutsideClick(ref, () => {
alert('You clicked outside')
});
@kevinfelisilda
kevinfelisilda / useResize.js
Created April 7, 2019 09:52
hook for triggering callback on browser resize
import { useEffect, useState } from 'react';
/**
* Usage:
*
* const ref = useRef();
*
* useResize(ref, (data) => {
* console.log(data.width);
* });
// yarn add styled-components
import styled from 'styled-components';
export default function() => {
return (
<Style>
<div className="blue">
This is blue text
@kevinfelisilda
kevinfelisilda / install-docker-in-linux.txt
Last active June 6, 2019 04:27
Install docker in linux
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
To check the status:
sudo systemctl status docker
Docker
https://docs.docker.com/docker-for-windows/install/
Git (Git Bash)
https://git-scm.com/downloads
Install tmux in bash
https://blog.pjsen.eu/?p=440
@kevinfelisilda
kevinfelisilda / json_array_to_sql_insert.js
Last active May 9, 2020 02:35
Convert JSON array data to SQL insert statement
/**
* This function only get attributes from the first item
* if not specified from the 3rd parameter
*/
function json_array_to_sql_insert(table_name, arr, _attributes) {
if (!Array.isArray(arr) || arr.length === 0){
throw new Error('Enter an array with atleast 1 item');
}
const attributes = _attributes || Object.keys(arr[0]);
let sql = `INSERT INTO \`${table_name}\` (${attributes.map(a => `\`${a}\``).join(', ')})\nVALUES`;