Skip to content

Instantly share code, notes, and snippets.

View solancer's full-sized avatar
🎯
Focusing

Srinivas Gowda solancer

🎯
Focusing
View GitHub Profile
@solancer
solancer / convert_lb3_to_lb4.py
Created August 20, 2024 14:01
Convert Loopback 3 to Loopback 4 model
# Updated function to handle missing `base` property in the model JSON files.
def convert_lb3_to_lb4(lb3_model_content):
model_name = lb3_model_content['name']
base_model = lb3_model_content.get('base', 'Entity')
base_model = 'Entity' if base_model == 'PersistedModel' else base_model
# Start building the TypeScript model
ts_model = f"import {{Entity, hasMany, hasOne, belongsTo, model, property}} from '@loopback/repository';\n"
# Collect imports for related models
@solancer
solancer / redis-setup.js
Created July 11, 2024 07:57
redlock - lock jobs
// In server/boot/redis-setup.js or any relevant file
const Redis = require('ioredis');
const Redlock = require('redlock');
// Initialize Redis
const redis = new Redis(); // Assumes Redis is running on default host and port
// Setup Redlock for distributed locks
const redlock = new Redlock(
@solancer
solancer / webProjectv3.txt
Created January 25, 2024 15:21
webProjectv3 tree2dir test
webProjectv3/
├── LICENSE.md
├── README.md
├── archetypes
│ └── default.md
├── docker-compose.yml
├── gulpfile.js
├── layouts
│ ├── 404.html
│ ├── blog
@solancer
solancer / project-tree.txt
Created January 23, 2024 13:28
project-tree.txt
project/
├── src
│ ├── controllers
│ │ └── yourController.js
│ ├── models
│ │ └── yourModel.js
│ ├── routes
│ │ └── yourRoute.js
│ ├── utils
│ │ └── database.js
webApp/
├── package.json
├── app/
│ ├── app.js
│ ├── views/
│ │ ├── home.html
│ │ └── about.html
│ └── models/
│ ├── user.js
│ └── product.js
@solancer
solancer / ReactConditionalRendering.js
Created December 9, 2022 07:14
React conditional rendering
export const RenderIf = ({ children, when }) => {
return when ? children : null
}
import RenderIf from '../components/RenderIf'
let userLoggedIn = false
<RenderIf when={userLoggedIn}>
<UserProfile />
@solancer
solancer / npmVersion.md
Created August 8, 2022 11:34 — forked from nmccready/npmVersion.md
npm version described

npm version

read https://docs.npmjs.com/cli/version it's very straight forward.

Everything in npm config cli is available to be set in .npmrc like preid.

IE this allows your to define your prerelease identifier. By default npm follows this format.

MAJOR.MINOR.PATCH-PRE

@solancer
solancer / usage.py
Created July 1, 2022 03:08
Django / Python Entity or ID Pattern
def my_fun(user_or_id: UserOrId):
user = get_user(user_or_id)
# Do something with user
# These both do the same thing (but the first avoids the extra db hit)
my_fun(user)
my_fun(user.id)
@solancer
solancer / concurrent_map_exception
Last active June 28, 2022 04:49
concurrent map
#!/usr/bin/env python3
'''
Usage:
./concurrent_map_exception.py [nproc [min [max]]
e.g.:
./concurrent_map_exception.py 2 -10 100
Outcome:
:80
encode gzip
root * /Users/shared/server/components/web
route {
reverse_proxy /soc/* 127.0.0.1:9710
reverse_proxy /api/* 127.0.0.1:9720
reverse_proxy /fio/* 127.0.0.1:9730
try_files {path} /index.html
file_server browse