Skip to content

Instantly share code, notes, and snippets.

View callezenwaka's full-sized avatar

Callis callezenwaka

View GitHub Profile
@callezenwaka
callezenwaka / Filter JavaScript Object
Last active July 3, 2021 09:43
How to filter out unwanted items from JavaScript object.
// filter out unnecessary key-value pairs
const omit = (obj, arr) =>
Object.keys(obj)
.filter(k => !arr.includes(k))
.reduce((acc, key) => ((acc[key] = obj[key]), acc), {});
let item = {name: 'John Doe', profession: 'Developer', age: 30, gender: 'male', height: '1.6m', weight: '80kg', country: 'UK'};
let filteredItem = omit(item, ['gender', 'height', 'weight', 'country']);
// console.log(filteredItem);
@callezenwaka
callezenwaka / Centered div
Last active July 12, 2021 20:51
How to center div with position absolute
<!DOCTYPE html>
<html>
<head>
<style>
.loader {
background-color: #000;
position: absolute;
height: 4rem;
width: 4rem;
left: 50%;
Refer to doc here <a href="https://firebase.google.com/docs/functions/config-env">Config Env. Setup</a>
# Set environment configuration for your project
```
firebase functions:config:set someservice.key="THE API KEY" someservice.id="THE CLIENT ID"
```
# Retrieve current environment configuration
```
firebase functions:config:get
@callezenwaka
callezenwaka / Padding numbers in JavaScript
Last active July 9, 2021 05:09
Number Padding In JavaScript
// Define new date, result
let d = new Date(), result;
// Set new date
d.setDate(d.getDate() + 20);
// Return result
result = ('0' + d.getDate()).slice(-2) + '/' + ('0' + (d.getMonth()+1)).slice(-2) + '/' + d.getFullYear();
Explanation:
.slice(-2) returns the last 2 characters of the string.
'use strict';
// Import packages
import admin from 'firebase-admin';
const FieldValue = admin.firestore.FieldValue;
// Add credential service account details
import serviceAccount from ".path-to-file.json";
// Initialize firebase admin sdk config
Setup a POST => request;
Replace firebase api key in the url => "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key={FIREBASE_API_KEY}"
Pass the following params in the body of the request
{
"email": "<email>",
"password": "<password>",
"returnSecureToken": true
}
@callezenwaka
callezenwaka / Event.vue
Created January 19, 2022 07:24
Handle events in Vue 3 with Typescript
<template>
<div class="body--wrapper" :class="{ active: !slide && !width }">
<Header"></Header>
<div class="container">
<router-view :key="$route.path"/>
</div>
</div>
</template>
<script lang="ts">
@callezenwaka
callezenwaka / index.html
Created January 19, 2022 09:05
Add space in html file
<!DOCTYPE html>
<html>
<head>
<title>
How to insert spaces/tabs in text using HTML/CSS?
</title>
</head>
<body>
<h1 style="color: green">GeeksforGeeks</h1>
<b>How to insert spaces/tabs in text using HTML/CSS?</b>
@callezenwaka
callezenwaka / Array.sol
Last active February 19, 2022 00:45
Handle array in javascript
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
*/
contract Array {
@callezenwaka
callezenwaka / index.js
Created September 7, 2022 16:20
React two-way data binding
import logo from "./logo.svg";
import "./App.css";
import { useState } from "react";
function App() {
const [food, setFood] = useState("dumpling");
return (
<div className="App">
<input