Skip to content

Instantly share code, notes, and snippets.

View StanleyMasinde's full-sized avatar
🎯
Focusing

Stanley Masinde StanleyMasinde

🎯
Focusing
View GitHub Profile
@StanleyMasinde
StanleyMasinde / setup-site.sh
Created June 19, 2025 22:33
Script to create a deploy a site to VPS via reverse proxy.
#!/usr/bin/env bash
set -euo pipefail
log() { echo -e "\033[1;32m[+]\033[0m $1"; }
err() { echo -e "\033[1;31m[!]\033[0m $1" >&2; }
[[ "$EUID" -eq 0 ]] || { err "Run as root"; exit 1; }
if [[ $# -lt 4 || $# -gt 8 ]]; then
err "Usage:"
@StanleyMasinde
StanleyMasinde / update-node.sh
Created June 19, 2025 20:16
Update Node cleanly.
#!/usr/bin/env bash
set -euo pipefail
ARCH="linux-x64"
BASE_URL="https://nodejs.org/download/release"
log() {
echo -e "\033[1;32m==>\033[0m $1"
}
@StanleyMasinde
StanleyMasinde / main.rs
Created June 17, 2025 13:42
task: concurrently compute and print the first 1000 prime numbers
use std::env::args;
use rayon::prelude::*;
fn is_prime(n: u64, primes: &[u64]) -> bool {
let sqrt = (n as f64).sqrt() as u64;
for &p in primes {
if p > sqrt {
break;
}
@StanleyMasinde
StanleyMasinde / webhook.yourdomain.com
Last active January 10, 2025 13:54
Reverse proxy
server {
listen 80;
server_name webhook.yourdomain.com;
location / {
proxy_pass http://localhost:9000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@StanleyMasinde
StanleyMasinde / xmlhttp.js
Created January 19, 2024 15:48
XMLHTTP Request
const req = new XMLHttpRequest()
req.addEventListener('load', (event) => {
console.log(event.target.response)
})
req.open('https://jsonplaceholder.typicode.com/posts')
req.send()
@StanleyMasinde
StanleyMasinde / promises.js
Created October 28, 2023 13:22
A simple test on Promise.all()
// Promises without dates
(async function main() {
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Promise 1')
}, 5000)
})
const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
name: Deploy
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
@StanleyMasinde
StanleyMasinde / deploy.sh
Last active June 4, 2022 19:16
A shell script to help in application deployment
#!/bin/sh
## Set error handling
set -e
## Set debug mode
#set -x
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
@StanleyMasinde
StanleyMasinde / smart-commit.sh
Created February 20, 2021 12:47 — forked from am-kantox/smart-commit.sh
Bash script that prefixes commits with a JIRA (CO-400)
#!/usr/bin/env bash
# based on https://github.com/sbimochan/smart-commit/blob/master/commit
# am@aleksei  feature/CO-400-some-branch-name$ ./smart-commit.sh "Foo bar."
# → [feature/CO-400-some-branch-name f70ebbf167] CO-400: Foo bar.
set -euo pipefail
if [ -z "${1:-}" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
@StanleyMasinde
StanleyMasinde / HandlePutFormData.php
Last active July 20, 2020 10:24 — forked from Stunext/HandlePutFormData.php
Laravel: Middleware to support multipart/form-data in PUT, PATH and DELETE requests
<?php
namespace App\Http\Middleware;
use Closure;
use Symfony\Component\HttpFoundation\ParameterBag;
/**
* @author https://github.com/Stunext
*