Skip to content

Instantly share code, notes, and snippets.

View nitishparkar's full-sized avatar

Nitish Parkar nitishparkar

View GitHub Profile
@nitishparkar
nitishparkar / blockchain.rb
Created November 16, 2021 19:10
Ruby version of Questbook's "Writing a blockchain in Python"
require 'digest'
require 'json'
class Chain
def initialize
@blockchain = []
@pending = []
end
def add_block(proof)
@nitishparkar
nitishparkar / keybindings.json
Created September 12, 2020 18:59
VSCode: Run different commands for the same shortcut key depending on language
[
{
"key": "ctrl+t",
"command": "go.test.cursor",
"when": "editorLangId == go"
},
{
"key": "ctrl+t",
"command": "extension.runSpecLine",
"when": "editorLangId == ruby"
@nitishparkar
nitishparkar / number_to_words.rb
Created June 27, 2020 14:57
Convert a number into english words (Indian numbering system) in ruby
# https://stackoverflow.com/a/43522719 + couple of fixes
def number_to_words(num)
numbers_to_name = {
10_000_000 => "crore",
100_000 => "lakh",
1000 => "thousand",
100 => "hundred",
90 => "ninety",
80 => "eighty",
@nitishparkar
nitishparkar / gofmt
Created June 18, 2019 14:36
Run gofmt and fix issues in all go files in the current directory and its subdorectories, excluding ./vendor
gofmt -w $(find . -type f -name '*.go' -not -path "./vendor/*")
@nitishparkar
nitishparkar / pluralsight_gorilla_toolkit_db
Created October 11, 2016 15:03
Create table samples for Pluralsight's gorilla toolkit course
CREATE TABLE employee(
id serial PRIMARY KEY NOT NULL,
given_name varchar(255),
surname varchar(255),
address text,
city varchar(255),
state varchar(255),
postal_code varchar(255),
role_id int,
hire_date date,
@nitishparkar
nitishparkar / android_icons_copier
Created December 3, 2014 06:51
A ruby script to copy icons to appropriate directories in android app
require "fileutils"
ICONS_DIR = "path-to-icons-dir" # Ex. "/home/nitish/Downloads/material-design-icons-1.0.0/"
PROJECT_RES_DIR = "path-to-res-dir-of-android-app" # Ex. "/home/nitish/Projects/android_app/app/src/main/res/"
DRAWABLES = ["drawable-hdpi", "drawable-mdpi", "drawable-xhdpi", "drawable-xxhdpi"]
COLORS = {
"grey" => "grey600",
"gray" => "grey600",
"black" => "black",
"white" => "white"
@nitishparkar
nitishparkar / rails-validation-errors
Created November 2, 2014 09:31
Rails: Displaying validation errors in admin panel using haml and bootstrap
.col-lg-12
- if @post.errors.any?
.alert.alert-danger
%ul
- @post.errors.full_messages.each do |message|
%li= message