Skip to content

Instantly share code, notes, and snippets.

View swistaczek's full-sized avatar

Ernest Bursa swistaczek

View GitHub Profile
@dhh
dhh / pagination_controller.js
Last active April 24, 2024 10:53
HEY's Stimulus Pagination Controller
/*
ERB template chunk from The Feed's display of emails:
<section class="postings postings--feed-style" id="postings"
data-controller="pagination" data-pagination-root-margin-value="40px">
<%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %>
<%= link_to(spinner_tag, url_for(page: @page.next_param),
class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %>
</section>
# Source: https://gist.github.com/0431989df4836eb82bdac0cc53c7f3d6
# Used in https://youtu.be/R6OeIgb7lUI
##############################
# Flux 2 With GitOps Toolkit #
##############################
# What Is GitOps And Why Do We Want It?: https://youtu.be/HKkhD6nokC8
# Argo CD: Applying GitOps Principles To Manage Production Environment In Kubernetes: https://youtu.be/vpWQeoaiRM4
@sorny
sorny / x11_forwarding_macos_docker.md
Last active May 15, 2024 08:29
X11 forwarding with macOS and Docker

X11 forwarding on macOS and docker

A quick guide on how to setup X11 forwarding on macOS when using docker containers requiring a DISPLAY. Works on both Intel and M1 macs!

This guide was tested on:

  • macOS Catalina 10.15.4
  • docker desktop 2.2.0.5 (43884) - stable release
  • XQuartz 2.7.11 (xorg-server 1.18.4)
  • Macbook Pro (Intel)
def ask_question question
print "#{question} "
return gets.chomp
end
def ask_exercise_level
puts "What's your exercise level (1-5)? "
puts ' 1. little or no exercise'
puts ' 2. exercise/sports 1 - 3 times per week'
puts ' 3. exercise/sports 4 - 5 times per week'
@jbelke
jbelke / Mac OSX Setup - Brew
Last active May 2, 2024 05:45
Mac OSX Setup - Brew and Cask
# Get Sudo.
if [ $EUID != 0 ]; then
sudo "$0" "$@"
exit $?
fi
# Install Xcode first - https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12
# Install Xcode command line tools.
xcode-select --install
@Saren-Arterius
Saren-Arterius / ubm-solver.py
Last active July 1, 2019 14:29
Unblock Me solver
#!/usr/bin/env python3
# An Unblock Me solver written using A* search algorithm
# perfect solution
# Author: Saren
SIZE = 6
"""
GOAL = (
(' ', ' ', ' ', ' ', ' ', ' '),
(' ', ' ', ' ', ' ', ' ', ' '),
(' ', ' ', ' ', ' ', 'T', 'G'),
@lloydmeta
lloydmeta / range.rb
Created December 24, 2013 02:11
Range validator for Grape.
class RangeValidator < Grape::Validations::Validator
def initialize(attrs, options, required, scope)
@range = options
@required = required
raise ArgumentError, "Range provided (#{@range.inspect}) does not implement #cover?" unless @range.respond_to? :cover?
super
end
def validate_param!(attr_name, params)
if (params[attr_name] || @required) && !@range.cover?(params[attr_name])
raise Grape::Exceptions::Validation,
@blaix
blaix / service-objects.md
Created June 12, 2013 11:04
Martin Fowler on Service Objects via the Ruby Rogues Parley mailing list

On Tue, Mar 12, 2013 at 1:26 PM, Martin Fowler martinfowlercom@gmail.com wrote:

The term pops up in some different places, so it's hard to know what it means without some context. In PoEAA I use the pattern Service Layer to represent a domain-oriented layer of behaviors that provide an API for the domain layer. This may or may not sit on top of a Domain Model. In DDD Eric Evans uses the term Service Object to refer to objects that represent processes (as opposed to Entities and Values). DDD Service Objects are often useful to factor out behavior that would otherwise bloat Entities, it's also a useful step to patterns like Strategy and Command.

It sounds like the DDD sense is the sense I'm encountering most often. I really need to read that book.

The conceptual problem I run into in a lot of codebases is that rather than representing a process, the "service objects" represent "a thing that does the process". Which sounds like a nitpicky difference, but it seems to have a real impact on how people us

@nzifnab
nzifnab / monkey_jammit.rb
Created May 7, 2011 08:38
Monkeypatch of Jammit to pre-compile using Haml
module Jammit
class Compressor
# Compiles a single JST file by writing out a javascript that adds
# template properties to a top-level template namespace object. Adds a
# JST-compilation function to the top of the package, unless you've
# specified your own preferred function, or turned it off.
# JST templates are named with the basename of their file.
# We are monkey-patching it so that we get Haml compilation *before* it hits the client.
def compile_jst(paths)
@hipertracker
hipertracker / gist:214210
Created October 20, 2009 12:05
NGinx -> TorqueBox
/etc/hosts:
127.0.0.1 myhost jboss_server
NGINX:
server {
listen myhost:80;
server_name myhost;
location / {
proxy_set_header X-Real-IP $remote_addr;