Skip to content

Instantly share code, notes, and snippets.

View squalvj's full-sized avatar
24/7

Aditya Wiraha squalvj

24/7
  • Jakarta
View GitHub Profile
@squalvj
squalvj / configureStore.js
Created December 31, 2018 16:50
Persisting redux store without using any dependencies
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { combineReducers, createStore } from 'redux'
import { Provider } from 'react-redux';
import todoReducer from './reducer/todoReducer'
import throttle from 'lodash/throttle'
@squalvj
squalvj / promise.js
Created November 23, 2018 05:45
Show and Hide loading using seperate promise file and using try and catch
function myPromise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Stack Overflow');
// reject('Some Error')
}, 2000);
});
}
function showSpinner() {
@squalvj
squalvj / XORCipher.js
Created November 7, 2018 07:04 — forked from sukima/XORCipher.js
A Super simple encryption cipher using XOR and Base64 in JavaScript
// XORCipher - Super simple encryption using XOR and Base64
//
// Depends on [Underscore](http://underscorejs.org/).
//
// As a warning, this is **not** a secure encryption algorythm. It uses a very
// simplistic keystore and will be easy to crack.
//
// The Base64 algorythm is a modification of the one used in phpjs.org
// * http://phpjs.org/functions/base64_encode/
// * http://phpjs.org/functions/base64_decode/
@squalvj
squalvj / nFormatter.js
Last active November 1, 2023 08:08
This function convert integer like 1000000 into 1M, 1K, etc
function nFormatter(num, digits) {
var si = [
{ value: 1, symbol: "" },
{ value: 1E3, symbol: "K" },
{ value: 1E6, symbol: "M" },
{ value: 1E9, symbol: "G" },
{ value: 1E12, symbol: "T" },
{ value: 1E15, symbol: "P" },
{ value: 1E18, symbol: "E" }
];
@squalvj
squalvj / change.php
Created September 30, 2018 05:46
Find all greater change given the total (using greedy algorithms)
<?php
function kembalian($jumlah){
$kembali = [];
$total = 0;
$obj = array(
[
'name' => 'G2',
'val' => 200,
],
[
@squalvj
squalvj / CoinChange.js
Created September 30, 2018 05:09
Coin Change Problem using greedy algorithm
var makeChange = function(amount) {
var change = [],
total = 0;
[25, 10, 5, 1].forEach(function(coin) {
while (total + coin <= amount) {
change.push(coin);
total += coin;
}
});
return change;
@squalvj
squalvj / validate.js
Last active September 22, 2018 05:49
Validate every element inside object inside array
let pOC = [
{
fullName: '',
type: {
name: ''
},
email: '',
mobileNo: '',
officeNo: '',
},
@squalvj
squalvj / app.js
Created September 16, 2018 06:30
simple auto reload server
//npm install --save-dev simple-autoreload-server
var launcher = require('simple-autoreload-server');
var server = launcher({
port: 8008,
path: './dist/html/',
});
module.exports = server;
@squalvj
squalvj / webpack.config.js
Created September 15, 2018 14:41
Webpack + Sass + Pug
const path = require('path');
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const pug = {
test: /\.pug$/,
use: [
'html-loader?attrs=false',
'pug-html-loader'
]
@squalvj
squalvj / webpack.config.js
Created September 15, 2018 13:15
Webpack config for SASS + Babel
const path = require('path');
module.exports = {
entry: './assets/js/dev/index.js',
output: {
filename: 'bundle.js',
// __dirname is a function that npm itself have in the library
path: path.resolve(__dirname, './assets/js/dist')
},
module: {