Skip to content

Instantly share code, notes, and snippets.

View dalsn's full-sized avatar
💭
Available

Dalhatu Njidda dalsn

💭
Available
View GitHub Profile
@lilpolymath
lilpolymath / LRUCache.md
Created April 12, 2022 14:30
Implementing a given cache size behaving as an LRU cache with an expiry time and auto cache burst

Question

Implement Promise based memoization with a given cache size behaving as an LRU cache with an expiry time and auto cache burst.

Answer

First, what we have to do is breakdown the terms in the problem statement to understand what is going on and what we are asked to do.

  1. Promise based memoization: Memoization is one of the ways we can improve the performance of functions by eliminating redundant calls. Memoization is a technique where we store the results of a function call in a cache and return the result from the cache if the function is called again with the same arguments.
@vicgonvt
vicgonvt / deployment_guide.md
Last active March 17, 2024 06:51
Deployment Guide for Ubuntu Server from Scratch with Laravel
@troatie
troatie / CreatesWithLock.php
Last active September 12, 2023 13:51
Guard against race conditions in Laravel's firstOrCreate and updateOrCreate
trait CreatesWithLock
{
public static function updateOrCreate(array $attributes, array $values = [])
{
return static::advisoryLock(function () use ($attributes, $values) {
// emulate the code found in Illuminate\Database\Eloquent\Builder
return (new static)->newQuery()->updateOrCreate($attributes, $values);
});
}
@arsho
arsho / Add SSH Key to Bitbucket OR Github in Ubuntu 16.04.md
Last active February 15, 2024 04:43
Step by step instructions to add SSH key files in Bitbucket or Github

Add SSH Key to Bitbucket / Github in Ubuntu 16.04

What does SSH Keys do in Github / Bitbucket?

Set up SSH to reduce the risk of exposing your username and password. Some reasons you might want to use SSH key base authentication:

  • Is more effective if you push and pull from Bitbucket many times a day.
  • Removes the need to enter a password each time you connect.
@dbshoupe
dbshoupe / Http.js
Last active October 2, 2021 16:07
Wrapper class for Axios in a Vue project that uses interceptor to inject token (stored using Vuex) into header for each request.
import axios from 'axios';
import store from "@/data/state"
class Http {
constructor() {
let service = axios.create({});
service.interceptors.request.use((config) => {
config.headers.common['x-access-token'] = store.state.token
return config
@wojteklu
wojteklu / clean_code.md
Last active May 19, 2024 16:37
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@bmaupin
bmaupin / build-openssl.sh
Last active December 11, 2023 20:24
Build openssl (with SSLv2/3 support for security testing)
#!/bin/bash
# Cache sudo password
sudo -v
# Get latest OpenSSL 1.0.2 version from https://openssl.org/source/
# v1.1.0 seems to have removed SSLv2/3 support
openssl_version=1.0.2k
# Install build dependencies
@FremyCompany
FremyCompany / readme.md
Last active June 15, 2022 06:26 — forked from DigiTec/readme.md

Spoiler pages for the FindNearbyWords challenge

The goal of the exercise is to find an efficient way to take an existing word and lookup all words in a dictionary that differ from the original by only a single character. This is the kernel function for larger algorithmic problems like the Word Ladder, where you try to find the shortest route between two words, by changing one character at a time, and where each intermediate step must be in an intial dictionary of words.

Bruce Force

The simplest algorithm possible will take the input word and then compare it against every word in the dictionary, character by character, and count the differences. If the character differences between the word are just 1, then we add it to our list, otherwise we reject it. JavaScript has the Array.filter method which does precisely what we want and we just supply a function which returns true or false depending on if our criterion are met.

It is possible to optimize differsByOne further to get more benefits, but given t