Skip to content

Instantly share code, notes, and snippets.

View catwhocode's full-sized avatar

Cat who code catwhocode

View GitHub Profile
<?php
// kalikan semua elemen array dengan bilangan 10
$arr = [1,2,3,4,5,6];
$arrow = array_map(fn($value) => $value * 10, $arr);
print_r($arrow);
@catwhocode
catwhocode / preview.html
Created October 30, 2021 04:17
Preview image before upload
<input type="file" id="imagefile" name="imagefile" onchange="preview()">
<img id="preview">
<script>
function preview() {
const imagefile = document.querySelector('#imagefile');
const preview = document.querySelector('#preview');
const objFileReader = new FileReader;
objFileReader.readAsDataURL(imagefile.files[0]);
@catwhocode
catwhocode / BlogPost.jsx
Created November 15, 2021 14:48
Notes from Prawito Hudoro's React Tutorial | Session 11
import React, {Component, Fragment} from 'react'
import Post from '../../component/Post/Post'
import axios from 'axios';
class BlogPost extends Component {
state = {
post: []
}
handleFetch = (url) => {
@catwhocode
catwhocode / Unprotect-VBA-on-XLSM.md
Last active November 22, 2021 15:58
Unprotect VBA on XLSM file
@catwhocode
catwhocode / Edit-SSHD-Config.md
Created November 23, 2021 06:44
Editing SSHD Config Programmatically
#!/usr/bin/env sh
file=/etc/ssh/sshd_config
cp -p $file $file.old &&
awk '
$1=="#PasswordAuthentication" {$1="PasswordAuthentication"; $2="no"}
$1=="#PubkeyAuthentication" {$1="PubkeyAuthentication"; $2="yes"}
{print}
' $file.old > $file
@catwhocode
catwhocode / addEntry.ps1
Created November 23, 2021 15:41
Add new entry to the path environment variable
# source:
# https://stackoverflow.com/questions/17240725/setx-doesnt-append-path-to-system-path-variable/17247259
$new_entry = 'd:\app'
$old_path = [Environment]::GetEnvironmentVariable('path', 'machine');
$new_path = $old_path + ';' + $new_entry
[Environment]::SetEnvironmentVariable('path', $new_path,'Machine');
@catwhocode
catwhocode / rest-argument.js
Created November 24, 2021 18:23
Using Javascript Three Dots As Rest Arguments
// source:
// https://dev.to/sagar/three-dots---in-javascript-26ci
function myFunc(a, b, ...args) {
console.log(a); // 22
console.log(b); // 98
console.log(args); // [43, 3, 26]
};
myFunc(22, 98, 43, 3, 26);
@catwhocode
catwhocode / destructuring-rest.js
Created November 24, 2021 19:10
Destructuring Rest Parameter
// source:
// https://dev.to/sagar/three-dots---in-javascript-26ci
function myFunc(...[x, y, z]) {
return x * y* z;
}
myFunc(1) // NaN
myFunc(1, 2, 3) // 6
myFunc(1, 2, 3, 4) // 6 (fourth parameter is not destructured)
@catwhocode
catwhocode / spread-operator.js
Created November 24, 2021 19:16
Using Spread Operator in Javascript
// source:
// https://dev.to/sagar/three-dots---in-javascript-26ci
function myFunc(x, y, ...params) { // used rest operator here
console.log(x);
console.log(y);
console.log(params);
}
var inputs = ["a", "b", "c", "d", "e", "f"];
@catwhocode
catwhocode / spread-operator-variable.js
Created November 24, 2021 19:27
Combining Array using Spread Operator
// source:
// https://dev.to/sagar/three-dots---in-javascript-26ci
const featured = ['Deep Dish', 'Pepperoni', 'Hawaiian'];
const specialty = ['Meatzza', 'Spicy Mama', 'Margherita'];
const pizzas = [...featured, 'veg pizza', ...specialty];
console.log(pizzas);