Skip to content

Instantly share code, notes, and snippets.

View sandys's full-sized avatar

Sandeep Srinivasa sandys

View GitHub Profile
@sandys
sandys / Fastapi-sqlalchemy-pydantic-dataclasses-reloadable-logging.md
Last active April 12, 2024 01:38
fastapi with python 3.10 dataclasses - used to create both sqlalchemy and pydantic models simultaneously. And setting up sqlalchemy the right way (without deadlocks or other problems). Additionally, this also takes care of unified logging when running under gunicorn..as well as being able to run in restartable mode.
@sandys
sandys / datadog.service
Last active March 19, 2023 20:10
Getting Datadog logs to work with Docker Swarm or journald
[Unit]
Description=Datadog Docker Swarm
After=systemd-journald.service
Requires=systemd-journald.service
[Service]
ExecStart=/bin/zsh -c "coproc while true; do ncat --ssl intake.logs.datadoghq.com 10516; done ;journalctl -o json -f | jq -r --unbuffered '\"c441ade4f5f4d04c \" + ({ message:.MESSAGE, service_name:.COM_DOCKER_SWARM_SERVICE_NAME, container:.CONTAINER_NAME, containerid:.CONTAINER_ID_FULL, host:._HOSTNAME,pid:(._PID // \"-\"), timestamp:(.__REALTIME_TIMESTAMP|tonumber/1000000|todate),\"syslog.severity\":((.PRIORITY|tonumber)) }|tostring)' >&p 2>&p"
@sandys
sandys / MOTA - Honest Voting.md
Last active January 27, 2023 09:08
MOTA (Many of the Above) or Honest Voting - an application of approval voting in India.

MOTA (Many of the Above) is Honest voting - you dont have to fear about vote wasting

This is very easy to describe to voters: vote for everyone you approve of.
MOTA does one thing very well - it removes any reason to vote against your favorite candidate.

Intuitive Explanation

In any voting system, if there's only ONE candidate - not voting and voting for the candidate are the same.
For TWO candidates - it is better to pick the one you like more.

@sandys
sandys / table_to_csv.rb
Created October 18, 2012 10:04
convert a html table to CSV using ruby
# run using ```rvm jruby-1.6.7 do jruby "-J-Xmx2000m" "--1.9" tej.rb```
require 'rubygems'
require 'nokogiri'
require 'csv'
f = File.open("/tmp/preview.html")
doc = Nokogiri::HTML(f)
csv = CSV.open("/tmp/output.csv", 'w',{:col_sep => ",", :quote_char => '\'', :force_quotes => true})
@sandys
sandys / IE8_on_ubuntu.md
Created June 20, 2012 06:40
Installing IE8 on Ubuntu 12.04 64-bit (and avoiding the 32/64 bit architecture error)
@sandys
sandys / scalafun.md
Created September 24, 2012 18:06
Notes for Scala functional programming coursera
  • if CBV terminates, then so does CBN - since CBN will evaluate less than or equal parameters than CBV
  • CBV avoids repeated recomputation of values
  • force scala to do CBN, by defining def fun(x:Int, y:=>Int)
  • disjunction and conjunction (&& and ||) are short-circuit operators - the right side will only be evaluated in certain cases.
  • in certain cases like
    if(r==0)
      return 1
    there is an error Scala: type mismatch; found : Unit required: Boolean
    • this happens because you have to have an else clause, otherwise the type checker doesn't know what the return type is when it's not the case
  • return fn(a-1) is tail recursive but return n * fn(a-1) is not
@sandys
sandys / email_attachments_ses_simple.php
Created January 23, 2013 10:33
Script to send email using Amazon SES with attachments in PHP
<?php
require("./amazon-sdk/sdk.class.php");
// on ubuntu - this script can be run using php5-cli and php5-curl
//Provide the Key and Secret keys from amazon here.
$AWS_KEY = "kkk";
$AWS_SECRET_KEY = "kkkk+xKcdkB";
//certificate_authority true means will read CA of amazon sdk and false means will read CA of OS
$CA = true;
1. If ur upgrading from an older fedora,
1.1 `sudo dnf remove docker-*`
1.2 `sudo dnf config-manager --disable docker-*`
1.2 please ensure `/etc/default/grub` doesnt contain `systemd.unified_cgroup_hierarchy=0`. If it does contain, then remove it and run `sudo grub2-mkconfig -o /boot/grub2/grub.cfg`
2. reboot
3. set firewall correctly using `sudo firewall-cmd --zone=docker --change-interface=docker0`
4. in `/etc/sysconfig/docker` please ensure `--live-restore` is removed
5. reboot
6. docker should work
@sandys
sandys / R_code.R
Created October 10, 2012 09:16
Coursera operations management notes
d <- data.frame(PT=c(3,2,5,1))
d <- data.frame(d, capacity=1/d$PT)
d$flow_rate <- min(d$capacity) # no demand numbers here
d <- data.frame(d, process_capacity=min(d$capacity))
d <- data.frame(d, cycle_time=1/d$process_capacity)
d <- data.frame(d, dlc=sum(d$PT))
d <- data.frame(d, idle_time=d$cycle_time-d$PT)
d <- data.frame(d, total_idle_time=sum(d$idle_time))
d <- data.frame(d, total_labor_content=sum(d$PT))
d <- data.frame(d, labor_util=d$total_labor_content/(d$total_labor_content+d$total_idle_time))
@sandys
sandys / dockerfile_ruby_rbenv.sh
Last active May 27, 2021 15:21
Dockerfile for a ruby/rbenv setup on ubuntu/debian
# DOCKER-VERSION 1.0
# run with curl <gist path> | docker build -t sandys/rbenv -
#when exiting/stopping a container it remains in the filesystem
#every time we run docker run a new container is created
#https://github.com/dotcloud/docker/issues/3258
#stop all containers docker stop $(docker ps -a -q)
#rm all containers docker rm $(docker ps -a -q)