Skip to content

Instantly share code, notes, and snippets.

View navsqi's full-sized avatar

Nauval Shidqi navsqi

View GitHub Profile
@navsqi
navsqi / helper.php
Last active July 20, 2018 08:26
Helper pada php
<?php
// base url
define("BASE_URL", "http://localhost/kuliahti/");
// format tanggal indonesia
function tanggal_indonesia($date)
{
$hari = array(
"Minggu",
"Senin",
@navsqi
navsqi / google_recaptcha.php
Last active July 29, 2018 12:18
Contoh implementasi Google re-Captcha
<?php
include "../function/connection.php";
include "../function/helper.php";
$site_key = '6LfKB2cUAAAAAAoh18m-HBnYmjgwRkWQabNKYeTF'; // Diisi dengan site_key API Google reCapthca yang sobat miliki
$secret_key = '6LfKB2cUAAAAADpVAwNAqpwjOE2o7o6Dj5on4Xvo'; // Diisi dengan secret_key API Google reCapthca yang sobat miliki
$ip = $_SERVER['REMOTE_ADDR']; // get IP user
$artikel_id = $_POST['artikel_id'];
@navsqi
navsqi / hyper.js
Last active November 4, 2019 10:56
hyper configuration for windows 10
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
@navsqi
navsqi / app.js
Last active December 14, 2019 08:36
Build RESTful API with Node.js
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const ejs = require("ejs");
const app = express();
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({extended: true}));
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
// Entry
entry: './src/index.js',
// Output
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@navsqi
navsqi / globalErrorSqlz.js
Created August 2, 2020 17:31
sequelize global error handling
// in models/index.js
if (sequelize) {
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch((err) => {
console.error('Unable to connect to the database:', err);
});
@navsqi
navsqi / apidocjs.js
Created August 12, 2020 06:30
Membuat dokumentasi API dengan APIdocJS
https://speakerdeck.com/rottmann/api-documentation?slide=14
https://indrakusuma.web.id/2017/11/09/Tutorial-Buat-Dokumentasi-RESTful-API-dengan-APIdocJS/
@navsqi
navsqi / 01.StoresMigration.js
Last active December 17, 2020 04:59
Sequelize guide examples.
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('stores', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
@navsqi
navsqi / 1.appError.js
Last active November 11, 2020 08:05
Error handling in Node.JS
class AppError extends Error {
constructor(message, statusCode) {
super(message);
this.statusCode = statusCode;
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error';
this.isOperational = true;
Error.captureStackTrace(this, this.constructor);
}