Skip to content

Instantly share code, notes, and snippets.

@MSeneadza
MSeneadza / production.rb
Created October 27, 2023 23:31 — forked from mudge/production.rb
How to configure Rails and Rack::Attack to use the real client IP when running behind Cloudflare
Rails.application.configure do
# Add Cloudflare's IPs to the trusted proxy list so they are ignored when
# determining the true client IP.
#
# See https://www.cloudflare.com/ips-v4/ and https://www.cloudflare.com/ips-v6/
config.action_dispatch.trusted_proxies = ActionDispatch::RemoteIp::TRUSTED_PROXIES + %w[
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
@MSeneadza
MSeneadza / postgres_queries_and_commands.sql
Created April 3, 2023 15:37 — forked from indigoviolet/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@MSeneadza
MSeneadza / linearregression.rb
Created December 8, 2020 19:55 — forked from scottsbaldwin/linearregression.rb
Ruby Linear Regression Calculator
# Adapted from a C# example here:
# http://stackoverflow.com/questions/43224/how-do-i-calculate-a-trendline-for-a-graph
# And thanks to John Esser for helping figure out how to
# calculate the targets to stabilize a negative slope!
class LinearRegression
attr_accessor :slope, :intercept
# Pass in an array of values to get the regression on
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@MSeneadza
MSeneadza / rspec_model_testing_template.rb
Created July 4, 2019 11:54 — forked from PWSdelta/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@MSeneadza
MSeneadza / postgres.sql
Created December 8, 2018 02:33 — forked from thomasbilk/postgres.sql
Solve Sudoku in SQL
WITH RECURSIVE x( s, ind ) AS
( SELECT sud, position( '.' IN sud )
FROM (SELECT '91.7......326.9.8...7.8.9...86.3.17.3.......6.51.2.84...9.5.3...2.3.149......2.61'::text
AS sud) xx
UNION ALL
SELECT substr( s, 1, ind - 1 ) || z || substr( s, ind + 1 )
, position('.' IN repeat('x',ind) || substr( s, ind + 1 ) )
FROM x
, (SELECT gs::text AS z FROM generate_series(1,9) gs) z
WHERE ind > 0
@MSeneadza
MSeneadza / postgresql-set-id-seq.sql
Last active May 21, 2018 12:46 — forked from henriquemenezes/postgresql-set-id-seq.sql
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table) + 1);
@MSeneadza
MSeneadza / gist:04c8a54edbc5937f4b7609b6435ae15b
Created December 10, 2017 15:10 — forked from waitingallday/gist:1851354
Kaminari on find_by_sql
sql = "…"
Kaminari.paginate_array(Product.find_by_sql(sql)).page(params[:page]).per(20)
/*jQuery UI autocomplete for bootstrap*/
.ui-autocomplete {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
display: none;
min-width: 160px;
@MSeneadza
MSeneadza / The Technical Interview Cheat Sheet.md
Created October 10, 2016 04:34 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.