This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# fetch entire website | |
# | |
# Example: | |
# fetch-website https://www.bharat.in | |
# | |
function fetch-website { | |
# Check if wget is available | |
if ! command -v wget &>/dev/null; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# tested with 8, 9, 10, 11, 12 digit phone numbers | |
# | |
# ar = ["(+1) 888 33x19", "95606 3354", "555 123 1234", "0 95606 33544", "(+91) 95606 33544"] | |
# ar.map {|e| format_string(e) } | |
# => ["188-833-19", "956-063-354", "555-123-12-34", "095-606-335-44", "919-560-633-544"] | |
# | |
def format_string(s) | |
# step #1 => remove all non-digits | |
# step #2(a) => pick the digits in groups of 333[2][2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# utility functions | |
# | |
# compress PDF using ghostscript | |
# | |
# https://ghostscript.readthedocs.io/en/latest/VectorDevices.html#controls-and-features-specific-to-postscript-and-pdf-input | |
# | |
# -dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi) | |
# -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi) | |
# -dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# a simple user factory | |
# factories/users.rb | |
# | |
FactoryBot.define do | |
factory :user do | |
name { Faker::Name.unique.name } | |
email { Faker::Internet.email(domain: "bharat.in") } | |
# some users will randomly be "admin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// matching the brackets | |
// * one type of brackets only | |
// * opening must appear before closing bracket | |
// * pre or post padding characters should not affect the result | |
// * any other characters in0between anywhere should not affect the result | |
// | |
const balanced = (arg) => { | |
// | |
// `for char of result` should also work here | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Goal: find matching enclosures | |
// * opening enclosure must appear before closing | |
// * multiple opening enclosures can appear, but must be closed in proper reverse order | |
// * any other text, character ot symbol should not affect the result | |
// * pre or post padding space or characters should not affect the result | |
const balanced = (string) => { | |
// example: { "{}": 0, "[]": 0, ...} | |
let enclosures = { "{}": 0, "[]": 0, "()": 0, "<>": 0 } | |
// stack of keys must match closing braces in the reverse order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [Leetcode #3](https://leetcode.com/problems/longest-substring-without-repeating-characters/) says | |
# Given a string s, find the length of the longest substring without repeating characters. | |
# | |
# Example 1: | |
# | |
# Input: s = "abcabcbb" | |
# Output: 3 | |
# Explanation: The answer is "abc", with the length of 3. | |
# | |
# Example 2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Faker: A ruby gem (MIT) to generate test data | |
# https://github.com/faker-ruby/faker | |
require "faker" | |
# generate a random set of words | |
# | |
# => ["temporibus", "laborum", "et", "facilis", "assumenda", "autem", "voluptatem"] | |
# | |
# words = rand(5..10).times.collect { Faker::Lorem.word } | |
words = Array.new(rand(5..10)) { Faker::Lorem.word } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'benchmark' | |
# synopsis | |
# | |
# rubocop suggested syntax is | |
# * costlier on execution | |
# * not really that super easy to read and maintain than case statement | |
# * adds more number of lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Bucket is a wrapper around Apartment::Tenant for utility methods | |
# | |
class Bucket | |
PUBLIC = "public".freeze | |
SYSTEM_NAMES_REGEX_PATTERN = 'information_schema|pg_\w+'.freeze | |
# | |
# Class methods | |
# |
NewerOlder