Skip to content

Instantly share code, notes, and snippets.

@nikolovlazar
nikolovlazar / serviceLocator.ts
Last active July 2, 2024 22:55
An updated ServiceLocator that matches types in the `getService` method
import { CollectionsRepository } from '../repositories/collectionsRepository'
import { AuthenticationService } from './authenticationService'
import { CollectionsService } from './collectionsService'
interface ServiceMap {
AuthenticationService: AuthenticationService
CollectionsService: CollectionsService
}
@nikolovlazar
nikolovlazar / serviceLocator.ts
Created June 28, 2024 16:30
Service Locator pattern in TypeScript
import { CollectionsRepository } from '../repositories/collectionsRepository'
import { AuthenticationService } from './authenticationService'
import { CollectionsService } from './collectionsService'
export class ServiceLocator {
private static _cache: Record<string, any>
static {
console.log('Setting up cache')
@nikolovlazar
nikolovlazar / keybindings.json
Last active July 2, 2024 06:28
VSCode key bindings to navigate like Neovim
[
// Navigation
{
"key": "ctrl-h",
"command": "workbench.action.navigateLeft"
},
{
"key": "ctrl-l",
"command": "workbench.action.navigateRight"
},
@nikolovlazar
nikolovlazar / slugify.js
Created January 13, 2024 18:42
An Obsidian QuickAdd script that renames the file/parent folder to its slugified version
// https://byby.dev/js-slugify-string
const slugify = function (str) {
return String(str)
.normalize("NFKD") // split accented characters into their base characters and diacritical marks
.replace(/[\u0300-\u036f]/g, "") // remove all the accents, which happen to be all in the \u03xx UNICODE block.
.trim() // trim leading or trailing whitespace
.toLowerCase() // convert to lowercase
.replace(/[^a-z0-9 -]/g, "") // remove non-alphanumeric characters
.replace(/\s+/g, "-") // replace spaces with hyphens
.replace(/-+/g, "-"); // remove consecutive hyphens
// Name: tmux sesh
// Description: Atach to a tmux session
// Author: Lazar Nikolov
// Twitter: @NikolovLazar
import '@johnlindquist/kit';
const sessionsCmd = await $`tmux list-sessions`;
let sessions = sessionsCmd.stdout
// Name: tmux sesh
// Description: Opens a tmux session
import '@johnlindquist/kit';
const sessionsCmd = await $`tmux list-sessions`;
let sessions = sessionsCmd.stdout;
sessions = sessions
.split('\n')
// Name: tmux sesh
// Description: Opens a tmux session
import '@johnlindquist/kit';
const sessionsCmd = await $`tmux list-sessions`;
let sessions = sessionsCmd.stdout;
sessions = sessions
.split('\n')
@nikolovlazar
nikolovlazar / dotfiles-install.sh
Last active June 16, 2023 01:14
Dotfiles installation script
git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim
git clone --bare https://github.com/nikolovlazar/dotfiles.git $HOME/.dotfiles
function dotfiles {
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME $@
}
mkdir -p .config-backup
@nikolovlazar
nikolovlazar / popover-anatomy-illustration.tsx
Created December 30, 2022 12:15
The Popover Anatomy illustration
<AspectRatio ratio={16 / 9}>
<svg
width='100%'
height='100%'
viewBox='0 0 298 216'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<rect width='298' height='216' fill='white' />
<path
@nikolovlazar
nikolovlazar / Modal.kt
Created November 21, 2022 12:24
An example Modal UI built with Jetpack Compose.
@Composable
fun Modal() {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(40.dp),
) {
Icon(
Icons.Filled.Email,
"icon",
tint = Color(52, 120, 246), // similar to the iOS one