Skip to content

Instantly share code, notes, and snippets.

View subratrout's full-sized avatar

Subrat Rout subratrout

View GitHub Profile
@subratrout
subratrout / tetris
Created November 4, 2022 18:58 — forked from JoshCheek/tetris
CLI tetris
View tetris
#!/usr/bin/env ruby
require 'io/console'
class Grid
def self.from_str(str, color:)
rows = str.lines.map do |line|
line.chomp.chars.map do |c|
color if c != " ".freeze
end
end
View most-viewed-stack-overflow-questions.sql
SELECT
'https://stackoverflow.com/questions/' + CONVERT(VARCHAR, Posts.Id) as url,
(
ViewCount / (SELECT -DATEDIFF(DAY, GETDATE() , CreationDate))
) AS ave_views_per_day,
*
FROM
Posts
LEFT JOIN PostTags ON Posts.Id = PostTags.PostId
LEFT JOIN Tags ON PostTags.TagId = Tags.Id
View searchkick_and_elasticsearch_guidance.md

Resources:

https://github.com/ankane/searchkick

Indexing

By default, simply adding the call 'searchkick' to a model will do an unclever indexing of all fields (but not has_many or belongs_to attributes).

In practice, you'll need to customize what gets indexed. This is done by defining a method on your model called search_data

def search_data

@subratrout
subratrout / imposter-handbook-links.md
Created April 25, 2021 16:36 — forked from milmazz/imposter-handbook-links.md
Useful links found in The Imposter's Handbook by Rob Conery
View imposter-handbook-links.md
@subratrout
subratrout / caesar.rb
Created April 16, 2021 11:58 — forked from matugm/caesar.rb
Caesar cipher using Ruby
View caesar.rb
ALPHABET_SIZE = 26
def caesar_cipher(string)
shiftyArray = []
charLine = string.chars.map(&:ord)
shift = 1
ALPHABET_SIZE.times do |shift|
shiftyArray << charLine.map do |c|
((c + shift) < 123 ? (c + shift) : (c + shift) - 26).chr
@subratrout
subratrout / ruby_meta.md
Created April 15, 2021 15:45 — forked from jamesyang124/ruby_meta.md
Ruby meta programming
View ruby_meta.md

#!/bin/ruby --verion => 2.0.0-p353

Self

In Ruby, self is a special variable that always references the current object.

  • Inside class or module definition, self refer to the Class or Module object.
  • Inside instance method, self refer to future instance object.
  • Inside class method, self refer to the class.i
@subratrout
subratrout / vanilla-js-cheatsheet.md
Created July 24, 2020 23:45 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet
View vanilla-js-cheatsheet.md
@subratrout
subratrout / django_deploy.md
Created March 29, 2020 22:48 — forked from bradtraversy/django_deploy.md
Django Deployment - Digital Ocean
View django_deploy.md

Django Deployment to Ubuntu 18.04

In this guide I will go through all the steps to create a VPS, secure it and deploy a Django application. This is a summarized document from this digital ocean doc

Any commands with "$" at the beginning run on your local machine and any "#" run when logged into the server

Create A Digital Ocean Droplet

Use this link and get $10 free. Just select the $5 plan unless this a production app.

@subratrout
subratrout / about.md
Created April 18, 2018 16:44 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
View about.md
@subratrout
subratrout / array_iteration_thoughts.md
Created April 3, 2018 06:16 — forked from mrmartineau/array_iteration_thoughts.md
Array iteration methods summarized
View array_iteration_thoughts.md

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and