Skip to content

Instantly share code, notes, and snippets.

@fredxinfan
fredxinfan / main.yaml
Created January 18, 2021 03:45 — forked from ArturT/main.yaml
GitHub Actions - how to run parallel tests in RSpec for Ruby on Rails project. See article how to run RSpec on GitHub Actions for Ruby on Rails app using parallel jobs https://docs.knapsackpro.com/2019/how-to-run-rspec-on-github-actions-for-ruby-on-rails-app-using-parallel-jobs or sign up at https://knapsackpro.com/?utm_source=github&utm_medium=…
# .github/workflows/main.yaml
name: Main
on: [push]
jobs:
vm-job:
runs-on: ubuntu-latest
# If you need DB like PostgreSQL then define service below.
@fredxinfan
fredxinfan / resize_nocrop_noscale
Created November 18, 2020 23:43 — forked from maxivak/resize_nocrop_noscale
Crop and resize an image using MiniMagick in Ruby on Rails. Two approaches.
def resize_nocrop_noscale(image, w,h)
w_original = image[:width].to_f
h_original = image[:height].to_f
if w_original < w && h_original < h
return image
end
# resize
image.resize("#{w}x#{h}")
@fredxinfan
fredxinfan / ecs-interactive-console.sh
Last active October 26, 2020 01:13 — forked from clarkdave/ecs-interactive-console.sh
ecs-interactive-console
#!/bin/bash -e
##
# Use this annotated script a base for launching an interactive console task on Amazon ECS
#
# more info: https://engineering.loyaltylion.com/running-an-interactive-console-on-amazon-ecs-c692f321b14d
#
# Requirements:
# - `jq` must be installed on both the client and server
##
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@fredxinfan
fredxinfan / vanilla-ajax-poll.js
Last active July 29, 2019 23:43 — forked from twmbx/vanilla-ajax-poll.js
Polling in JS with an async ajax call that returns a promise ( modified from: https://davidwalsh.name/javascript-polling )
// The polling function
function poll(fn, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
var checkCondition = function(resolve, reject) {
var ajax = fn();
// dive into the ajax promise
ajax.then( function(response){
// If the condition is met, we're done!
@fredxinfan
fredxinfan / docker-for-mac.md
Created June 5, 2018 10:34 — forked from BretFisher/docker-for-mac.md
Getting a Shell in the Docker for Mac Moby VM

2018 Update: Easiest option is Justin's repo and image

Just run this from your Mac terminal and it'll drop you in a container with full permissions on the Moby VM. This also works for Docker for Windows for getting in Moby Linux VM (doesn't work for Windows Containers).

docker run -it --rm --privileged --pid=host justincormack/nsenter1

more info: https://github.com/justincormack/nsenter1


---
- \w*aclit\w*
- \w*adick\w*
- \w*aids\w*
- \w*alabama porch monkey\w*
- \w*anal intruder\w*
- \w*anal invader\w*
- \w*analicker\w*
- \w*anus\w*
- \w*4r5e\w*
require "json"
require "benchmark"
def measure(no_gc = false, &block)
if no_gc
GC.disable
else
GC.enable
# collect memory allocated during library loading
# and our own code before the measurement
@fredxinfan
fredxinfan / Rakefile.rb
Created September 1, 2015 01:51
Using ActiveRecord tasks outside of Rails
require 'yaml'
require 'logger'
require 'active_record'
include ActiveRecord::Tasks
class Seeder
def initialize(seed_file)
@seed_file = seed_file
end

VIM Editor Commands

Text Entry Commands (Used to start text entry)

a Append text following current cursor position

A Append text to the end of current line

i Insert text before the current cursor position