Skip to content

Instantly share code, notes, and snippets.

View barrsan's full-sized avatar
🏡
Working from home

Alex Baretsky barrsan

🏡
Working from home
View GitHub Profile
@barrsan
barrsan / fastapi-redis.py
Created March 22, 2025 12:54 — forked from nicksonthc/fastapi-redis.py
FastAPI with asyncio Redis and Lifespan Example
from contextlib import asynccontextmanager
from datetime import datetime
from fastapi import FastAPI, Request
import fastapi
from fastapi.datastructures import State
from fastapi.responses import JSONResponse
import redis.asyncio as redis
class Redis:
redis_client: redis.Redis = None
@barrsan
barrsan / Trie.js
Created June 9, 2023 14:04 — forked from tpae/Trie.js
Trie.js - super simple JavaScript implementation
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie
// -----------------------------------------
// we start with the TrieNode
function TrieNode(key) {
// the "key" value will be the character in sequence
this.key = key;
@barrsan
barrsan / SingletonModuleScopedInstance.js
Created March 8, 2023 18:58 — forked from dmnsgn/SingletonModuleScopedInstance.js
ES6 singleton pattern: constructor return an instance scoped to the module
// http://amanvirk.me/singleton-classes-in-es6/
let instance = null;
class SingletonModuleScopedInstance {
constructor() {
if (!instance) {
instance = this;
}
this._type = 'SingletonModuleScopedInstance';
<script>
;(function() {
// locomotive scroll storage
var loco_scroll = {};
// wait until sfe_loco_scroll available
var chck_if_sfe_loco_scroll_loaded = setInterval(function() {
if (window.sfe_loco_scroll && Object.keys(window.sfe_loco_scroll).length !== 0 && window.gsap && window.ScrollTrigger) {
@barrsan
barrsan / GSAP Full Screen Scrolliing
Created November 17, 2022 10:29 — forked from royce002/GSAP Full Screen Scrolliing
Parallax GSAP Scroll Trigger
<body>
<nav>
<img src="https://bit.ly/2NKLFXr" alt="">
<div>
<ul id="ul-menu">
<li><a id="menu_link" href="#section_beaches">Beaches</a></li>
<li><a id="menu_link" href="#section_temples">Civlization</a></li>
<li><a id="menu_link" href="#section_places">Places</a></li>
</ul>
@barrsan
barrsan / category.js
Created July 1, 2022 08:15 — forked from beppek/category.js
Example of how to query multi level nested documents in Sanity
import { FcTreeStructure } from 'react-icons/fc';
export default {
name: 'category',
title: 'Category',
type: 'document',
icon: FcTreeStructure,
fields: [
{
name: 'title',
@barrsan
barrsan / postgres-cheatsheet.md
Created March 14, 2020 14:42 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@barrsan
barrsan / tsconfig.json
Created February 7, 2020 11:18 — forked from KRostyslav/tsconfig.json
tsconfig.json с комментариями.
// Файл "tsconfig.json":
// - устанавливает корневой каталог проекта TypeScript;
// - выполняет настройку параметров компиляции;
// - устанавливает файлы проекта.
// Присутствие файла "tsconfig.json" в папке указывает TypeScript, что это корневая папка проекта.
// Внутри "tsconfig.json" указываются настройки компилятора TypeScript и корневые файлы проекта.
// Программа компилятора "tsc" ищет файл "tsconfig.json" сначала в папке, где она расположена, затем поднимается выше и ищет в родительских папках согласно их вложенности друг в друга.
// Команда "tsc --project C:\path\to\my\project\folder" берет файл "tsconfig.json" из папки, расположенной по данному пути.
// Файл "tsconfig.json" может быть полностью пустым, тогда компилятор скомпилирует все файлы с настройками заданными по умолчанию.
// Опции компилятора, перечисленные в командной строке перезаписывают собой опции, заданные в файле "tsconfig.json".
@barrsan
barrsan / Enhance.js
Created March 1, 2017 08:40 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {