Skip to content

Instantly share code, notes, and snippets.

View hwclass's full-sized avatar

Barış Güler hwclass

View GitHub Profile
# Step 1
# create main branch locally, taking the history from master
git branch -m master main
# Step 2
# push the new local main branch to the remote repo (GitHub)
git push -u origin main
# Step 3
# switch the current HEAD to the main branch
// if user accepts, this will give `persistent` (true/false, 1/0) back to the promise itself
if (navigator.storage && navigator.storage.persist) {
navigator.storage.persist().then((persistent) => {
if (persistent) {
// let the user know about what will happen
"Great! You will never loose your data even after clearing the cache of your browser."
} else {
"Ups, you need to activate storage within your browser to get notified."
}
@hwclass
hwclass / web-local-push.js
Last active October 10, 2022 12:32
Code piece for easily self-notification implementation
// the function which enables us to send notification to the user in every 30 seconds
function randomNotification() {
const notifTitle = 'Title here';
const notifBody = `Body here...`;
const notifImg = 'http://image-url-here/static/image.png';
const options = {
body: notifBody,
icon: notifImg,
};
new Notification(notifTitle, options);
@hwclass
hwclass / indexedDB.js
Created October 10, 2022 10:48
A boilerplate on how to deal with IndexedDB
const request = indexedDB.open("FlightApp", 1);
request.onerror = function (event) {
console.error("An error occurred with IndexedDB");
console.error(event);
};
request.onupgradeneeded = function () {
const db = request.result;
const store = db.createObjectStore("flights", { keyPath: "id", autoIncrement:true });
@hwclass
hwclass / index.jsx
Created June 5, 2022 22:50
Error: read ECONNRESET
// ...
export const getStaticProps = async () => {
const ECONNRESET_ERROR_SKIP_PAYLOAD = {
props: { hede: true }
}
try {
process.on('uncaughtException', (err) => console.log('message here...', err));
return ECONNRESET_ERROR_SKIP_PAYLOAD
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
pbcopy < ~/.ssh/id_rsa.pub
Go to the Github profile and update the RSA key there by adding a new name for it
const fs = require('fs');
const { exec } = require('child_process');
const readline = require('readline');
const {google} = require('googleapis');
const envs = [
'testing',
'production'
]
const currentUrl = https://blacklane.com/?maintenance_mode=on&foo=baz
function removeQueryString(currentUrl, removeThis) {
const url = new URL(currentUrl);
const query_string = url.search;
const search_params = new URLSearchParams(query_string);
search_params.delete(maintenance_mode);
url.search = search_params.toString();
curl -L https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh > /tmp/nvm-install.sh && bash /tmp/nvm-install.sh