Skip to content

Instantly share code, notes, and snippets.

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

Rohan Rajpal rohanrajpal

🏠
Working from home
View GitHub Profile
@esamattis
esamattis / Dockerfile
Last active April 3, 2025 14:54
How to deploy a single app to a container from a pnpm monorepo using `pnpm deploy` in Github Actions
FROM node:14-slim
ENV NODE_ENV=production
COPY pnpm-deploy-output /app
WORKDIR /app
ENTRYPOINT ["/app/entrypoint.sh"]
@stephane-vanraes
stephane-vanraes / hooks.js
Created May 3, 2022 11:34
Prefers-Color-Scheme Client Hint and SvelteKit
/**
See https://wicg.github.io/user-preference-media-features-headers/ for more info on the Client Hint
This code will inform the server which color scheme the user prefers.
It can be used to apply to correct classes and prevent a flash of the wrong scheme during load.
*/
export async function handle({ event, resolve }) {
// Read the Color Scheme Client Hint
const colorScheme = event.request.headers.get('Sec-CH-Prefers-Color-Scheme')
import { writable } from "svelte/store";
import { browser } from "$app/environment";
//string
export const userName = writable(
(browser && localStorage.getItem("userName")) || "hello world"
);
userName.subscribe((val) => browser && (localStorage.userName = val));
// array
@rohanrajpal
rohanrajpal / .ideavimrc
Last active August 17, 2021 09:46
My idea vimrc setup
"" Source your .vimrc
"source ~/.vimrc
"" -- Suggested options --
" Show a few lines of context around the cursor. Note that this makes the
" text scroll if you mouse-click near the start or end of the window.
"set number relativenumber
set idearefactormode=keep
set ideajoin
set incsearch
@CryogenicPlanet
CryogenicPlanet / .eslintrc
Created June 6, 2021 12:29
Typescript Mono Repo Guide
// .eslintrc
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"react-app",
"plugin:react/recommended",
@milancermak
milancermak / app-session.ts
Last active December 8, 2022 03:00
Custom session storage for a Shopify app in SQL using Prisma
import { PrismaClient } from '@prisma/client'
import Shopify from '@shopify/shopify-api'
import { Session } from '@shopify/shopify-api/dist/auth/session';
const prisma = new PrismaClient({ log: ['info', 'warn', 'error'] })
async function storeCallback(session: Session): Promise<boolean> {
const payload: { [key: string]: any } = { ...session }
return prisma.appSession.upsert({
create: { id: session.id, payload: payload },
@hassanrazadev
hassanrazadev / latest_conversation.sql
Last active July 4, 2024 03:25
Get latest conversation with last message per user. (MySQL query)
SELECT
*
FROM
messages,
(
SELECT
MAX(id) as lastid
FROM
messages
WHERE
@obokaman-com
obokaman-com / start_ngrok_update_cloudflare.sh
Created December 4, 2020 19:32
Script to start ngrok, copy the generated URL to clipboard and update a remote Cloudflare worker with the public ngrok url
#!/usr/bin/env bash
echo "=========== START LOCAL HTTP / HTTPS TUNNEL AND UPDATE YOUR REMOTE DEV DOMAIN TO POINT IT ==========="
printf "\n"
# Start NGROK in background
echo "⚡️ Starting ngrok"
ngrok http 8080 > /dev/null &
# Wait for ngrok to be available
while ! nc -z localhost 4040; do
@joshnuss
joshnuss / httpStore.js
Last active October 11, 2023 11:29
A Svelte store backed by HTTP
import { writable } from 'svelte/store'
// returns a store with HTTP access functions for get, post, patch, delete
// anytime an HTTP request is made, the store is updated and all subscribers are notified.
export default function(initial) {
// create the underlying store
const store = writable(initial)
// define a request function that will do `fetch` and update store when request finishes
store.request = async (method, url, params=null) => {
@pinkhominid
pinkhominid / index.js
Created September 24, 2019 10:15
Upload a file with node-fetch and form-data
const fs = require('fs');
const fetch = require('node-fetch');
const FormData = require('form-data');
const filePath = `path/to/file.ext`;
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append('field-name', fileStream, { knownLength: fileSizeInBytes });