Skip to content

Instantly share code, notes, and snippets.

@rajaravivarma-r
rajaravivarma-r / guestbook-fastapi.py
Last active July 9, 2025 16:43
Guestbook FAST API equivalent
#!/usr/bin/python3
# Scroll to the bottom for benchmarking results.
import html
import os
import aiosqlite
from datetime import datetime
from typing import List, Optional
from contextlib import asynccontextmanager
@rajaravivarma-r
rajaravivarma-r / fastapi-logging-middleware.py
Created March 11, 2024 17:52
FASTApi with logging in middleware
import logging
import asyncio
import json
from asyncio import sleep
from fastapi import FastAPI, APIRouter, Request, File, UploadFile
from fastapi.routing import APIRoute
from fastapi.encoders import jsonable_encoder
from fastapi.responses import (
@rajaravivarma-r
rajaravivarma-r / slices-pic.go
Created November 3, 2023 10:33
Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers.
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
a := make([][]uint8, dy)
for i := range a {
a[i] = make([]uint8, dx)
}
for i := 0; i < dy; i++ {
@rajaravivarma-r
rajaravivarma-r / memusg
Created April 25, 2023 06:33 — forked from netj/memusg
memusg -- Measure memory usage of processes
#!/usr/bin/env bash
# memusg -- Measure memory usage of processes
# Usage: memusg COMMAND [ARGS]...
#
# Author: Jaeho Shin <netj@sparcs.org>
# Created: 2010-08-16
############################################################################
# Copyright 2010 Jaeho Shin. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
This file has been truncated, but you can view the full file.
emails = [
".impo-text",
"0-00.usa.cc",
"0-180.com",
"0-30-24.com",
"0-420.com",
"0-900.com",
"0-aa.com",
"0-attorney.com",
"0-mail.com",
require 'spec_helper'
require 'pry'
describe "Workflows" do
context "when all jobs finish successfuly" do
it "marks workflow as completed" do
flow = TestWorkflow.create
perform_enqueued_jobs do
flow.start!
end
@rajaravivarma-r
rajaravivarma-r / .rubocop.yml
Created March 24, 2020 15:29
Preferred rubocop configuration
require:
- rubocop-performance
- rubocop-rails
AllCops:
TargetRubyVersion: 2.6
Exclude:
- "config/**/*.rb"
- "db/**/*.rb"
- "**/Rakefile"
# from http://zzapper.co.uk/vimtips.html
------------------------------------------------------------------------------
" new items marked [N] , corrected items marked [C]
" *best-searching*
/joe/e : cursor set to End of match
3/joe/e+1 : find 3rd joe cursor set to End of match plus 1 [C]
/joe/s-2 : cursor set to Start of match minus 2
/joe/+3 : find joe move cursor 3 lines down
/^joe.*fred.*bill/ : find joe AND fred AND Bill (Joe at start of line)
/^[A-J]/ : search for lines beginning with one or more A-J
@rajaravivarma-r
rajaravivarma-r / qt_split_string.cpp
Created August 21, 2019 11:22
Qt code to split string into parts, into parts of a particular length
#include <QDebug>
#include <QString>
#include <QStringList>
#include <QRegularExpression>
#include <QRegularExpressionMatchIterator>
#include <QFile>
class StringSplit {
public:
StringSplit(QString string) {
@rajaravivarma-r
rajaravivarma-r / faraday_sample_requests.rb
Created January 23, 2019 07:36
How to make different types of requests in faraday without using block.
require 'json'
require 'faraday'
connection = Faraday.new do |conn|
conn.adapter Faraday.default_adapter
end
# GET request
response = connection.get('https://httpbin.org/get', data: 'this is the data')
puts "Response from get: #{response.body}"