Skip to content

Instantly share code, notes, and snippets.

View akshayKhot's full-sized avatar
🎯
Focusing

Akshay Khot akshayKhot

🎯
Focusing
View GitHub Profile
#!/usr/bin/env ruby
require "net/ssh"
branch = `git rev-parse --abbrev-ref HEAD`.chomp
unless branch == 'main'
puts "oops! you're on a different branch. Merge your changes into main and then try again."
puts "exiting.."
return
end
require "money"
Money.locale_backend = nil
Money.rounding_mode = BigDecimal::ROUND_HALF_UP
module ProgrammingRuby
module Refactoring
class InvoicePrinter
def statement(invoice, plays)
total_amount = 0
@akshayKhot
akshayKhot / Procfile
Created January 22, 2022 19:10
Procfile
# api
web: bundle exec puma -C config/puma.rb
css: tailwindcss -i app/assets/stylesheets/application.css -o app/assets/stylesheets/wind.css --watch
js: yarn build --watch
# databases
redis: bundle exec redis-server
postgres: postgres -D /usr/local/var/postgres
# background jobs
@akshayKhot
akshayKhot / wrapper.rb
Created September 21, 2021 11:10
We need some way to know that the changes we make really improve performance.
require "json"
require "benchmark"
def measure(&block)
no_gc = (ARGV[0] == "--no-gc")
if no_gc
GC.disable
else
# collect memory allocated during library loading
@akshayKhot
akshayKhot / After.cs
Last active September 11, 2019 19:24
class Employee
{
void ProcessData()
{
var processor = new Processor(name, code, salary, ...);
processor.ProcessData();
}
}
class Processor
@akshayKhot
akshayKhot / Before.cs
Last active September 11, 2019 19:18
Code showing the Method Object pattern
class Employee
{
void ProcessData()
{
string name;
int code, salary;
// lots of other local variables...
// process name
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var formatDate = d3.time.format("%d-%b-%y");
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
$(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{
$(<span class="string">'#container'</span>).highcharts({
xAxis: {
categories: [<span class="string">'Jan'</span>, <span class="string">'Feb'</span>, <span class="string">'Mar'</span>, <span class="string">'Apr'</span>, <span class="string">'May'</span>, <span class="string">'Jun'</span>,
<span class="string">'Jul'</span>, <span class="string">'Aug'</span>, <span class="string">'Sep'</span>, <span class="string">'Oct'</span>, <span class="string">'Nov'</span>, <span class="string">'Dec'</span>]
},
series: [{
name: <span class="string">'Tokyo'</span>,
letter frequency
A .08167
B .01492
C .02782
D .04253
E .12702
F .02288
G .02015
H .06094
I .06966
@akshayKhot
akshayKhot / index.html
Last active May 7, 2017 01:07
Basic Line Chart
<!DOCTYPE>
<html>
<head>
<meta charset='UTF-8'>
<title>D3</title>
<link rel='stylesheet' href='style.css'>
</head>
<body>
<svg width='960' height='500'></svg>