Skip to content

Instantly share code, notes, and snippets.

View mfaridzia's full-sized avatar
📒
storyteller

Muhammad Farid Zia mfaridzia

📒
storyteller
View GitHub Profile
@jenhjlim
jenhjlim / index.html
Created September 4, 2018 10:20
[Vuex Net Ninja Tutorial] 8. Mapping Actions & Getters
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>vuex-playlist</title>
</head>
<body>
<div id="app"></div>
<script src="/dist/build.js"></script>
</body>
@deanhume
deanhume / service-worker-register.js
Last active August 25, 2019 01:32
Register a Service Worker
<script>
// Register the service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
const express = require('express');
const app = express();
const server = app.listen(3001, function() {
console.log('server running on port 3001');
@unscriptable
unscriptable / ambiguous-race.js
Last active September 25, 2019 13:20 — forked from briancavalier/ambiguous-race.js
Promise.race is a lie
// This is the function we will use to call Promise.race().
// logWinner is simply a function that races two promises
// and logs the "winner" of the race as a side effect.
function logWinner (p1, p2) {
Promise.race([p1, p2]).then(console.log.bind(console));
}
// Here are 2 promises, p1 and p2. p2 always resolves
// first, since p1 resolves in 20 ms, and p2 resolves
// in 10 ms. By any reasonable definition of "race",
@Mayankgupta688
Mayankgupta688 / react_useMemoryImplementation.jsx
Last active September 28, 2019 17:23
react_useMemoImplementation.jsx
import React, { useState, useMemo } from "react";
export default function SimpleStateHooks() {
const [count, setCount] = useState(1000);
function returnValue(inputValue) {
return inputValue + 10;
}
var calculatedValue = useMemo(() => returnValue(10), [10]);
@fuad-ardiono
fuad-ardiono / version.json
Created November 27, 2019 16:50
Build versioning vue
{
"coreVersion": "1",
"enhancementNumber": 1,
"date": "2019-11-27T16:33:20.906Z",
"version": "1.1.191128"
}
@alexisduque
alexisduque / vscode-update
Created March 14, 2017 08:25
Update VSCode on Ubuntu
#!/bin/bash
function code-up() {
wget https://vscode-update.azurewebsites.net/latest/linux-deb-x64/stable -O /tmp/code_latest_amd64.deb
sudo dpkg -i /tmp/code_latest_amd64.deb
}
export -f code-up
@Sparragus
Sparragus / eslint-plugin.js
Created October 28, 2017 06:37
Eslint plugin with a rule that enforces blank lines between sibling JSX elements
const JSXELEMENT_CHILDREN = [
'JSXText',
'JSXExpressionContainer',
'JSXSpreadChild',
'JSXElement',
'JSXFragment'
]
const isJSXElementChildrenType = x => x && JSXELEMENT_CHILDREN.includes(x.type)
module.exports = {
@shiftyp
shiftyp / cart.js
Last active June 17, 2020 07:22
A shopping cart with server persistence built with React hooks
import { useReducer, useState, useEffect } from "react";
const reduceCartFromOrders = (current, [id, quantity]) => {
if (current === null) current = {};
if (quantity === null) {
delete current[id];
return current;
}
@emre
emre / golang_binary_search.go
Last active October 13, 2020 23:10
binary search implementation on golang slices
package main
import (
"fmt"
)
func BinarySearch(target_map []int, value int) int {
start_index := 0
end_index := len(target_map) - 1