Skip to content

Instantly share code, notes, and snippets.

View barfi's full-sized avatar
💭
oh my...

Mr. Barfi barfi

💭
oh my...
View GitHub Profile
@barfi
barfi / array-unique.ts
Last active October 21, 2023 11:16
Array unique members
const uniqueFilter = (value: T, index: number, source: T[]): bolean => {
return source.indexOf(value) === index
}
// Example
const sourceArr = [1, 2, 3, 3, 4, 4, 4, 5]
const uniqueArr = sourceArr.filter(uniqueFilter) // [1, 2, 3, 4, 5]
@barfi
barfi / index.ts
Last active October 13, 2023 13:59
TS string literals re-mapping
type UserStruct = {
'prefix:name': string
'prefix:age': number
lastName: string
}
type RemovePrefix<T> = T extends `prefix:${infer U}` ? U : T
type RemovePrefixFromStruct<T> = {
[K in keyof T as RemovePrefix<K>]: T[K]
@barfi
barfi / typed-eventemitter-subclass.md
Last active July 26, 2023 17:12
Typed eventemitter subclass
// Map all your event names with their handlers

type CustomEmitterEvents = {
  eventA: (payload: number) => void
  eventB: (payload: string) => void
  eventC: (arg: boolean, msg: string) => void
}

// Interface of your sublcass, matches the EventEmitter method signatures
@barfi
barfi / rock_paper_scissors.md
Last active March 7, 2023 00:31
Rock paper scissors
// Case with 3 objects
const abc = (p1, p2, map = { a:0, c:1, b:2 }) => {
  return ['DRAW', 'P1', 'P2'][(map[p1] - map[p2] + 3) % 3]
}
// Case with 4 objects
const abcd = (p1, p2, map = { a:0, d:1, c:2, b:3 }) => {
 return ['DRAW', 'P1', 'P2'][(map[p1] - map[p2]) % 2 &amp;&amp; (4 - ((map[p1] - map[p2] + 4) % 4)) % 3 + 1]
@barfi
barfi / github_bitbucket_multiple_ssh_keys.md
Created January 30, 2023 14:57 — forked from yinzara/github_bitbucket_multiple_ssh_keys.md
Managing SSH keys and repo cloning using multiple accounts on GitHub and BitBucket

Why Multiple SSH keys?

There are numerous reasons you may need to use multiple SSH keys for accessing GitHub and BitBucket

You may use the same computer for work and personal development and need to separate your work.

When acting as a consultant, it is common to have multiple GitHub and/or BitBucket accounts depending on which client you may be working for.

You may have different projects you're working on where you would like to segregate your access.

@barfi
barfi / form.vue
Created August 1, 2020 00:03
Vuex complex form two way data binding with extend computed property
<template>
<form>
<input
v-for((val, key) in model)
:key="key"
:value="val"
@input="model = ({ [key]: $event })"
>
</form>
</template>
@barfi
barfi / transitions.scss
Created April 1, 2018 01:53 — forked from vieron/transitions.scss
Sass-mixins-for-vendor-prefixed transitions-including-properties
@function prefix($property, $prefixes: (webkit moz o ms)) {
$vendor-prefixed-properties: transform background-clip background-size;
$result: ();
@each $prefix in $prefixes {
@if index($vendor-prefixed-properties, $property) {
$property: -#{$prefix}-#{$property}
}
$result: append($result, $property);
}
@return $result;
@barfi
barfi / meta-tags.md
Created March 28, 2018 22:32 — forked from lancejpollard/meta-tags.md
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta name="keywords" content="your, tags"/>
<meta name="description" content="150 words"/>
<meta name="subject" content="your website's subject">
<meta name="copyright"content="company name">
<meta name="language" content="ES">
@barfi
barfi / README.md
Created March 26, 2018 03:01 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@barfi
barfi / git-console.txt
Last active February 14, 2018 21:01
Git console commands
------------------------------------------------------------------------
Basic
------------------------------------------------------------------------
git init
инициализирует git в текущем каталоге (не забыть в консоле перейти в текущий каталог!!!)
git status
Показывает текущий статус измененных файлов проекта (кто в stage, кто нет)