Skip to content

Instantly share code, notes, and snippets.

View deadkff01's full-sized avatar
🪐

Dennis Kaffer deadkff01

🪐
View GitHub Profile
@deadkff01
deadkff01 / .prettierrc
Created July 19, 2019 13:05
Prettier config
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false
}
@deadkff01
deadkff01 / jstricks.js
Last active June 3, 2019 03:13
JS tricks
const getUser = emailIncluded => ({
name: 'dead',
surname: 'kff01',
...(emailIncluded ? { email : '[email protected]' } : null)
})
console.log(getUser(true))
// destructuring
const rawUser = {
@deadkff01
deadkff01 / Defer.js
Created January 21, 2019 01:30
Simple defer imlementation
class Deferred {
constructor(){
this.canceled = false
this.promise = new Promise((resolve, reject) => {
this.resolve = (value) => {
if(!this.canceled) resolve(value)
}
this.reject = (value) => {
if(!this.canceled) reject(value)
}
@deadkff01
deadkff01 / reset-div.css
Created December 26, 2018 19:03
Reset all div styles
#my-div * {
animation : none;
animation-delay : 0;
animation-direction : normal;
animation-duration : 0;
animation-fill-mode : none;
animation-iteration-count : 1;
animation-name : none;
animation-play-state : running;
animation-timing-function : ease;
@deadkff01
deadkff01 / getElementsByClassName.js
Last active December 10, 2018 13:12
Get DOM elements by class name
// recursive method
const getElementsByClassNameRec = (className) => {
let nodeList = []
function find(node) {
if (node.classList && node.classList.contains(className))
nodeList.push(node)
for (let i = 0; i < node.childNodes.length; i++)
find(node.childNodes[i])
return nodeList
}
@deadkff01
deadkff01 / HashTable.js
Created November 29, 2018 01:33
HashTable with JavaScript
class HashTable{
constructor(size=42){
this.buckets = new Array(size)
this.size = size
}
hash(key){
return key.toString().length % this.size;
}
@deadkff01
deadkff01 / index.js
Created October 23, 2018 04:50
JavaScript Generators
let https = require('https')
const httpGetAsync = (url, callback) => {
return https.get(url,
(response) => {
var body = ''
response.on('data', (d) => {
body += d
})
response.on('end', () => {
@deadkff01
deadkff01 / index.html
Created September 28, 2018 00:59
Vue Add List Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
@deadkff01
deadkff01 / index.js
Created August 22, 2018 14:41
React - Simple count with Redux
import React, { Component } from 'react';
import { render } from 'react-dom';
import { createStore, combineReducers } from 'redux';
import { connect, Provider } from 'react-redux';
const countReducer = (state = { count: 0 }, action) => {
switch (action.type) {
case 'INC': return { count: state.count + 1 };
case 'DEC': return { count: state.count - 1 };
default: return state;
@deadkff01
deadkff01 / index.html
Last active August 15, 2018 14:38
Simple get with fetch API
<button type="button" id="btn">Show my IP</button>
<div id="ipContainer"></div>
<script>
const btn = document.getElementById('btn')
const ipContainer = document.getElementById('ipContainer')
const fetchJSON = async (req) => {
const request = await fetch(req)
return request.json();
}