Skip to content

Instantly share code, notes, and snippets.

View al3rez's full-sized avatar

Alireza Bashiri al3rez

View GitHub Profile
@rphlmr
rphlmr / clear-db.ts
Last active April 30, 2024 14:41
Drizzle snippets
// Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406
import { sql } from "drizzle-orm";
const clearDb = async (): Promise<void> => {
const query = sql<string>`SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type = 'BASE TABLE';
`;
@vadv
vadv / fsm.md
Created January 29, 2020 07:44

Finite state machine in PostgreSQL

This document will not disclose the topic why you need fsm.

But if you implement fsm, then you need to do it as nearly as possible in the data.

This document will explain how you can implement it with PostgreSQL and gives developers maximum freedom.

Schema

@jamesmacfie
jamesmacfie / README.md
Created October 22, 2019 02:53
iTerm 2 - script to change theme depending on Mac OS dark mode

How to use

In iTerm2, in the menu bar go to Scripts > Manage > New Python Script

Select Basic. Select Long-Running Daemon

Give the script a decent name (I chose auto_dark_mode.py)

Save and open the script in your editor of choice.

@al3rez
al3rez / main.cr
Created December 13, 2017 19:00
Building a RESTful API with Crystal
require "http/server"
class Users::Me
include HTTP::Handler
def call(context)
return call_next(context) unless match?(context.request)
STDOUT.puts "getting user info..."
STDOUT.puts "done!"
@pesterhazy
pesterhazy / ripgrep-in-emacs.md
Last active March 21, 2024 18:25
Using ripgrep in Emacs using helm-ag (Spacemacs)

Why

Ripgrep is a fast search tool like grep. It's mostly a drop-in replacement for ag, also know as the Silver Searcher.

helm-ag is a fantastic package for Emacs that allows you to display search results in a buffer. You can also jump to locations of matches. Despite the name, helm-ag works with ripgrep (rg) as well as with ag.

How

@JosephDunivan
JosephDunivan / adjacentElementsProduct.rb
Last active May 4, 2021 15:08
Ruby finds the largest product of two adjacent numbers in an array in linear time O(1)
#finds the largest product of two adjacent numbers in an array
def adjacentElementsProduct(inputArray)
inputArray.each_cons(2).map { |x, y| x*y }.max
end
@fernandoaleman
fernandoaleman / fix-libv8-mac.txt
Created May 5, 2016 15:14
Fixing libv8 and therubyracer on Mac
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
" replace 'function' with λ
au BufNewFile,BufRead *.js syntax keyword javasScriptFunction function conceal cchar=λ
au BufNewFile,BufRead *.js hi! link javasScriptFunction Conceal
au BufNewFile,BufRead *.js setlocal conceallevel=2
" add abbreviations for JS
" f_
" expands to
" function() {
" <cursor>
"
@monokrome
monokrome / .Xdefaults
Created June 23, 2012 22:23
Mimicing iTerm2's pastel color scheme in RXVT/RXVT-Unicode
rxvt.background: #000000
rxvt.foreground: #D3D2D3
rxvt.color0: #000000
rxvt.color1: #FF7768
rxvt.color2: #ABFA68
rxvt.color3: #FFFD88
rxvt.color4: #98D0FE
rxvt.color5: #FF85FD
rxvt.color6: #CACBFE
rxvt.color7: #EFEFEF