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
let data = [
{
id: 1,
name: 'test',
category: 'Kitchen'
},
{
id: 2,
name: 'Bacon',
category: 'Fork'
import 'babel-polyfill'
//dont forget to import babel-polyfill for this Set
[... new Set(this.props.data.map(e => e.gender))]
@squalvj
squalvj / React, SetState Callback
Created September 14, 2018 15:39
React, SetState Callback
_onClickHandler: function _onClickHandler() {
console.log('State before (_onClickHandler): ' + JSON.stringify(this.state));
this.setState({
dollars: this.state.dollars + 10
}, () => {
console.log('Here state will always be updated to latest version!');
console.log('State after (_onClickHandler): ' + JSON.stringify(this.state));
});
}
@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: {
@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 / 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 / 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 / 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 / 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 / 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" }
];