Skip to content

Instantly share code, notes, and snippets.

@nisanthchunduru
nisanthchunduru / logo.svg
Created March 14, 2026 22:34
Logo (Draft)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kamal deploy
Log into image registry...
INFO [43ba0482] Running docker --version && docker buildx version as chunisan@localhost
INFO [43ba0482] Finished in 0.263 seconds with exit status 0 (successful).
INFO [78be9720] Running docker login -u [REDACTED] -p [REDACTED] as chunisan@localhost
INFO [78be9720] Finished in 3.187 seconds with exit status 0 (successful).
INFO [335cb57f] Running docker login -u [REDACTED] -p [REDACTED] on 150.136.2.200
INFO [335cb57f] Finished in 3.772 seconds with exit status 0 (successful).
Build and push app image...
INFO [57fe232e] Running docker --version && docker buildx version as chunisan@localhost
// TODO: Migrate to AWS Node SDK V3
const AWS = require('aws-sdk');
const cloudformation = new AWS.CloudFormation()async function disableTerminationProtection(stackNames) {
for (const stackName of stackNames) {
try {
await cloudformation.updateTerminationProtection({
EnableTerminationProtection: false,
StackName: stackName,
}).promise();
console.log(`Termination protection disabled for stack ${stackName}`);
@nisanthchunduru
nisanthchunduru / neural_network.py
Created November 13, 2023 10:18
Simple Neutral Network from scratch
# This program was generated by ChatGPT
import numpy as np
# Sigmoid activation function
def sigmoid(x):
return 1 / (1 + np.exp(-x))
# Derivative of the sigmoid function
def sigmoid_derivative(x):
@nisanthchunduru
nisanthchunduru / application.rb
Created June 26, 2023 12:44
Log responses in Rails in development environment
# In config/application.rb
class ResponseLogger
def initialize(app)
@app = app
end
def call(env)
headers = env.select {|k,v| k.start_with? 'HTTP_'}
.map {|pair| [pair[0].sub(/^HTTP_/, ''), pair[1]].join(": ")}
@nisanthchunduru
nisanthchunduru / teach_web_dev.md
Last active May 17, 2023 01:56
Teach web dev

Structs & functions

#include <stdio.h>
#include <string.h>

int stringsTotalLength(char* firstString, char* secondString) {
  int totalLength = strlen(firstString) + strlen(secondString);
  return totalLength;
}
@nisanthchunduru
nisanthchunduru / gist:d341ab22dede19e572d0e8152393e93a
Created June 8, 2021 13:40 — forked from ryanbriones/gist:246599
send email to gmail (STARTTLS) using ruby >=1.8.7
# send email using STARTTLS; Net::SMTP#enable_starttls requires ruby >=1.8.7
# this hack is needed for rails <2.3; apparently >=2.3 has something for this already
ActionMailer::Base.class_eval do
private
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
@nisanthchunduru
nisanthchunduru / redis-server
Last active March 7, 2019 13:26
Redis init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@nisanthchunduru
nisanthchunduru / bounce_events.rb
Last active October 31, 2018 14:09
Missing "smtp_id" key
{
"_json" => [{
"email" => "lovis@tinybuddy.se",
"timestamp" => 1540907117,
"status" => "4.3.0",
"reason" => "maildrop: maildir over quota.",
"sg_message_id" => "kxRB0RumSp6z8tkmLZnUMQ.filter0176p3mdw1-22850-5BD1C50F-7C.0",
"sg_event_id" => "QcLgvoOaRWCXLZ72J-lf1g",
"type" => "blocked",
"event" => "bounce"

Better SSH Authorized Keys Management

A seemingly common problem that people encounter is how to handle all of your users authorized_keys file.

People struggle over management, ensuring that users only have specific keys in the authorized_keys file or even a method for expiring keys. A centralized key management system could help provide all of this functionality with a little scripting.

One piece of functionality overlooked in OpenSSH is the AuthorizedKeysCommand configuration keyword. This configuration allows you to specify a command that will run during login to retrieve a users public key file from a remote source and perform validation just as if the authorized_keys file was local.

Here is an example directory structure for a set of users with SSH public keys that can be shared out via a web server: