Skip to content

Instantly share code, notes, and snippets.

View Mifrill's full-sized avatar

(Alex/Alexey) Aleksei (Stree’Jacque) Strizhak Mifrill

View GitHub Profile
#!/bin/bash -e
# Kubernetes api server is supposed to run compaction on etcd
# when that does not happen we need to do an emergency compaction to make etcd not lock up
# this should only be done once, so we pick the leader to do it, which we assume is healthy
# (compacting manually outside of api server can lead to watches failing / requests for specific revisions failing etc)
#
# After compacting the keyspace, the backend database may exhibit internal fragmentation.
# Any internal fragmentation is space that is free to use by the backend but still consumes storage space.
# The process of defragmentation releases this storage space back to the file system.
@nbibler
nbibler / caller.hbs
Created November 5, 2020 17:15
Video.js, TypeScript, traditional Ember Component
<MyVideo @video={{someVideoModelInstance}}/>
@tgroshon
tgroshon / oop_code_smells.md
Last active November 24, 2021 09:19
OOP Code Smells by Martin Fowler and Kent Beck grouped by Mika Mantyla

OOP Code smells

Things that might indicate a problem. RailsConf talk "Get a Whiff of This" by Sandi Metz

  • Couplers: binds objects together
    • feature envy (send more messages to object than to self)
    • inappropriate intimacy (access private methods/data)
    • message chains (law of demeter; too many dots)
    • middle man (sole purpose to forward on calls)
// tests/helpers/push-mirage-db-into-store.js
import { registerAsyncHelper } from '@ember/test';
import { run } from '@ember/runloop';
let pushMirageDbIntoStore = function(server, store) {
let tables = Object.keys(server.schema);
tables.forEach(table => {
if (server.schema[table].all) {
let all = server.schema[table].all();
@ccyrille
ccyrille / zero_downtime_remove_column.rb
Created February 7, 2018 16:34
Zero Downtime - Remove a column
class User < ActiveRecord::Base
...
# << REMOVE ON NEXT RELASE
def self.columns
super.reject { |c| c.name == "removed_column" }
end
# >> REMOVE ON NEXT RELEASE
...
end
@samselikoff
samselikoff / README.md
Last active June 24, 2020 19:56
How to use an `asyncThrows` custom helper.

This assert.asyncThrows custom assertion allows us to write tests against failing async code, usually as a result of a server error (4xx/5xx response).

test('If the index route errors, I see a message', async function(assert) {
  server.create('post');
  server.get('/posts/:id', { errors: ['The site is down'] }, 500); // force Mirage to error

  await assert.asyncThrows(() => {
    return visit('/posts/1');
 }, 'GET /posts/1 returned a 500');
@atinux
atinux / async-foreach.js
Last active August 30, 2024 13:03
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@asselstine
asselstine / hotfix.sh
Last active April 3, 2020 12:12
hotfix workflow
# My Heroku git production remote is called 'production'
git remote -v
# Yields:
#
# origin [email protected]:Loft47/loft.git (fetch)
# origin [email protected]:Loft47/loft.git (push)
# production https://git.heroku.com/loft47-prod.git (fetch)
# production https://git.heroku.com/loft47-prod.git (push)
# staging https://git.heroku.com/vey-staging.git (fetch)
@wbotelhos
wbotelhos / clear-sidekiq-jobs.sh
Last active October 23, 2024 14:10
Clear Sidekiq Jobs
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@mankind
mankind / rails-jsonb-queries
Last active November 12, 2024 13:02
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")