Skip to content

Instantly share code, notes, and snippets.

View r6m's full-sized avatar
🏠
Working from home

Reza r6m

🏠
Working from home
  • localhost
View GitHub Profile
@r6m
r6m / rke2-commands.md
Created June 29, 2024 07:08 — forked from superseb/rke2-commands.md
RKE2 commands

RKE2 commands

  • Updated on May 29 to accommodate etcd container not having /bin/sh available anymore.

Install

curl -sL https://get.rke2.io | sh
systemctl daemon-reload
systemctl start rke2-server
@r6m
r6m / google-oauth.controller.ts
Created September 16, 2023 20:53 — forked from thisismydesign/google-oauth.controller.ts
OAuth2 in NestJS for social login (Google, Facebook, Twitter, etc) /1
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { Request, Response } from 'express';
import { GoogleOauthGuard } from './google-oauth.guard';
@Controller('auth/google')
export class GoogleOauthController {
constructor(private jwtAuthService: JwtAuthService) {}
@Get()
@UseGuards(GoogleOauthGuard)
@r6m
r6m / golang_minimize_allocations.md
Created February 15, 2023 08:59 — forked from CAFxX/golang_minimize_allocations.md
Minimize allocations in Go

📂 Minimize allocations in Go

Protobuf

Working with protobuf in Go puts significant load on the memory subsystem, as protobuf-generated structures often contain a significant amount of pointers.

One way to minimize the number of allocations is to allocate all the fields at the same time, and then use internal pointers to wire them up.

@r6m
r6m / README.md
Created January 22, 2023 07:49
grpc gateway cors
import (
 // ...
 "github.com/rs/cors" 
)

// ...
mux := runtime.NewServeMux()
proto.RegisterXYZServiceHandler(ctx, mux, conn)

Practice Consul, Nomad in Production Part 1- Setup Cluster

This cluster will be set up for 3 servers, each server will run (Nomad server/client + Consul server/client)

Server Information

workload-info

Plans

@r6m
r6m / throttled_transport.go
Created August 28, 2022 09:49 — forked from zdebra/throttled_transport.go
NewThrottledTransport wraps transportWrap with a rate limitter, improvement of https://gist.github.com/MelchiSalins/27c11566184116ec1629a0726e0f9af5 since it allows use of *http.Client
package main
import (
"net/http"
"time"
"golang.org/x/time/rate"
)
// ThrottledTransport Rate Limited HTTP Client
@r6m
r6m / slice.sh
Last active May 8, 2022 03:48
split image by width using imagemagic
function slice() {
local slice_width="${SLICEW:-1080}"
local width=$(identify -format "%[w]" $1)
local slices=$(($width/$slice_width))
local name="${1%.*}"
echo -e "slice ($slices x $slice_width) for image $1"
convert -crop "${slices}x1@" $1 "${name}-%d.png"
}
@r6m
r6m / sources.list
Created April 17, 2022 08:02
ubuntu default sources.list
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
## or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
@r6m
r6m / username-regex.md
Created January 7, 2022 11:11
username regex validator
# https://stackoverflow.com/a/12019115/2272992 by Awk
^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$
 └─────┬────┘└───┬──┘└─────┬─────┘└─────┬─────┘ └───┬───┘
       │         │         │            │           no _ or . at the end
       │         │         │            │
       │         │         │            allowed characters
       │         │         │
 │ │ no __ or _. or ._ or .. inside

Integrating Slate into a Rails app

Want to use the excellent rich text editor Slate in a Rails app? Beware – since you'll be integrating React with your Rails app, it'll turn out pretty complicated and you'll have to do things (e.g. start server, managing dependencies, etc.) a bit differently than before. Let's start.

1. Install react_on_rails

react_on_rails is pretty much the best option for integrating React into Rails. Install it like so:

  1. Add this to your gemfile: