Skip to content

Instantly share code, notes, and snippets.

View nisanthchunduru's full-sized avatar

Nisanth Chunduru nisanthchunduru

View GitHub Profile
@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:

@nisanthchunduru
nisanthchunduru / strip_photo_metadata.rb
Created October 1, 2017 13:50
Strip location information and additional metadata from your photos using ruby
# Install imagemagick first
# brew install imagemagick
require "shellwords"
photos_dir = "ENV['Home']/Downloads/Photos to Upload"
Dir["#{photos_dir}/**/*"].each do |file_path|
system("mogrify -strip #{Shellwords.shellescape(file_path)}")
end
@nisanthchunduru
nisanthchunduru / clone_and_restore_server_harddisk.md
Last active August 1, 2023 07:52
Clone and restore a physical server's harddisk

Clone a server's harddisk

Login to Hetzner's web interface https://robot.your-server.de/ and activate the Rescue System for the server whose disk you wish to clone.

Ssh into the Rescue System (Replace 1.2.3.4 in the command below with the actual ip address of the server)

ssh -o HostKeyAlias=hetzner-rescue.1.2.3.4 root@1.2.3.4
@nisanthchunduru
nisanthchunduru / decode_session_cookie.rb
Created August 30, 2017 13:18
Decode Session Cookie in Rails 3