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 / 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 / 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 / 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 / takeString.js
Created January 2, 2019 06:10
Take the last string using split and splice
const url = 'auth/user/ucok';
const lastStr = url.split("/").slice(-1)[0];
// output 'ucok'
@squalvj
squalvj / formula.js
Created January 8, 2019 14:55
Algorithm calculate third number based on min max and convert them to percent
// basic
var max = 250
var min = 50
var input = 65
var percent = ((input - min) * 100) / (max - min)
// a little longer
var range = max - min
var correctedStartValue = input - min
var percentage = (correctedStartValue * 100) / range
@squalvj
squalvj / JavascriptTruthyness.js
Created June 3, 2019 06:29
Javascript Truthiness
1 == 1 //->true
1 == "1" //->true
1 == true//-> true
1 == 0 //-> false
1 == [] //-> false
@squalvj
squalvj / wow.test.js
Created July 24, 2019 10:30
Test manipulating state with jest
mport React from 'react';
import { shallow, mount, render } from 'enzyme';
import Todo from '../components/Todo';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
test('Test it', async () => {
@squalvj
squalvj / fibonacci.js
Created July 25, 2019 05:22
Fibonacci on js
function fibonacci(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
num--;
}
@squalvj
squalvj / fade.js
Created July 26, 2019 06:39
Animation Fade out using font-size 0
import React, { useState } from "react";
import ReactDOM from "react-dom";
import { Transition } from "react-transition-group";
import "./styles.css";
function App() {
const [visible, setVisible] = useState(true);
return (
@squalvj
squalvj / time.js
Created April 15, 2020 04:25
Minute, Second, Hour Calculation
const time = 3600 //second 1 hour
var minutes = Math.floor(time / 60);
//And to get the remaining seconds, multiply the full minutes with 60 and subtract from the total seconds:
var seconds = time - minutes * 60;
//Now if you also want to get the full hours too, divide the number of total seconds by 3600 (60 minutes/hour · 60 seconds/minute) first, then calculate the remaining seconds:
var hours = Math.floor(time / 3600);