Skip to content

Instantly share code, notes, and snippets.

View christos's full-sized avatar

Christos Zisopoulos christos

View GitHub Profile
@kddnewton
kddnewton / json.rb
Last active October 6, 2023 09:25
JSON parser with pattern matching
require "json"
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] }
source = JSON.dump(struct)
tokens = []
index = 0
until source.empty?
tokens <<
@karlseguin
karlseguin / waf.conf
Created October 22, 2021 13:02
basic nginx waf
# WAFs are a waste of time. False positives negatively impact actual users.
# And for what? Protection against vulnerabilities that, if you still have
# in this day in age, you're in more trouble than you think.
# Still, to keep my logs clean, I like to run something like the follwoing:
location ~ \.php$ { access_log off; return 444; }
location ~ \.asp$ { access_log off; return 444; }
location ~ \.aspx$ { access_log off; return 444; }
location ~ /Admincenter/ { access_log off; return 444; }
location /console/ { access_log off; return 444; }
@Envek
Envek / login_helpers.rb
Created October 11, 2021 06:42
Signing-in user for integration tests via cookie-only session with Rails, Devise, Capybara, and Cuprite
# spec/system/support/login_helpers.rb
# See this blog post for setup guide: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing
module LoginHelpers
def login_as(user)
# Craft session cookie to make request authenticated (to pass even routing constraints)
# Compilation of these:
# - https://dev.to/nejremeslnici/migrating-selenium-system-tests-to-cuprite-42ah#faster-signin-in-tests
# - https://turriate.com/articles/2011/feb/how-to-generate-signed-rails-session-cookie
# - https://github.com/rails/rails/blob/43e29f0f5d54294ed61c31ddecdf76c2e1a474f7/actionpack/test/dispatch/cookies_test.rb#L350
@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>

Honest is looking for a Rails contractor (3-month, 40h/week commitment)

Honest is building the “customer service agent’s best friend”: contextual, real-time assistance and shortcuts for digital customer service teams.

We’re looking for an experienced Rails contractor to come help us improve our Rails app, initially with a 3-month, 40h/week commitment. We’ll appreciate an inclination for “foundation” work (enhancing performance, increasing test coverage, improving our CI/CD pipeline…) although there’s plenty to do in user-facing features too.

Honest is built as a pretty standard Rails 6 “beautiful monolith” hosted in Github and running on Heroku, powered by PostgreSQL and Redis. You’ll have the chance to acquire experience on newer stuff like Hotwire too.

You’ll be part of a small, fully-remote team coordinating mainly via Discord and Jira. You’ll work along with colleagues with plenty of experience in the different aspects of building digital products. We keep a healthy, respectful,

Senior Backend Developer at Devengo

Devengo is a startup focused on a simple but ambitious mission: make finance a fairer place. Founded by well-known fintech players Fernando Cabello-Astolfi and Alberto Molpeceres our first product is an innovative social benefit that allows workers to collect their earned wages in real-time. Your money, when you need it.

The problem

Economists identify¹ three main challenges any person and household must face to reach a sustainable level of financial wellness: having sufficient and stable income, maintaining an economic-financial balance that limits problems of overindebtedness and avoiding severe poverty.

The last two challenges are the most pressing ones as they have an immediate effect on the material living conditions of the population and they compound over time sinking the households' economies further and further.

In Spain al

@bomberstudios
bomberstudios / DNI-Electronico-en-Mac.md
Last active October 30, 2023 10:38
Instrucciones para instalar el DNI Electrónico en un Mac en 2021

DNI Electrónico en Mac

El lector que voy a usar es el SVEON SCT011M, que es el mas barato que encontré en tienda física y tiene un precio razonable en Amazon: https://www.amazon.es/dp/B072LTLZW3/

Estos son los pasos que he seguido:

  1. Descargar Firefox (he probado con la ultima version, 86.0.1)
  2. Enchufar el lector, sin el DNI (no se si es importante hacerlo aquí o se puede hacer luego, pero mejor no nos arriesgamos, yo lo hice aquí y me ha funcionado)
  3. Descargar libpkcs11 para Intel o para Apple Silicon. Estos enlaces estan en la web oficial del DNI Electrónico por si quieres ver si hay alguna versión más reciente.
  4. Instalar el paquete (los ficheros se copiaran en /Library/Libpkcs11-dnie, y en esa misma carpeta se instalara una app para desinstalarlo en e

To symlink SSH_AUTH_SOCK on boot to system-wide switch the value from default ssh agent:

  1. Change /opt/homebrew/ to the correct homebrew path (/opt/homebrew is for Apple Silicon and /usr/local for x86)
  2. Change the ssh agent as needed, this example uses https://github.com/FiloSottile/yubikey-agent
  3. Save as ~/Library/LaunchAgents/link-ssh-auth-sock.plist
  4. Run launchctl load -F ~/Library/LaunchAgents/link-ssh-auth-sock.plist

Technique taken from: https://evilmartians.com/chronicles/stick-with-security-yubikey-ssh-gnupg-macos

@searls
searls / do-this.js
Created May 24, 2020 04:05
How to play web audio that won't interrupt background system-wide audio playback in iOS
let audioContext
export function play (url) {
const AudioContext = window.AudioContext || window.webkitAudioContext
if (!audioContext) audioContext = new AudioContext()
const request = new window.XMLHttpRequest()
request.open('GET', url, true)
request.responseType = 'arraybuffer'
request.addEventListener('load', function (e) {
const source = audioContext.createBufferSource()
source.buffer = audioContext.createBuffer(request.response, false)
@stympy
stympy / url_checker.rb
Last active May 2, 2021 19:45
Ruby class to check URL validity
require "ipaddr"
require "resolv"
require "uri"
class UrlChecker
SCHEME_REGEX = Regexp.new(/\Ahttps?/)
HOST_REGEX = Regexp.new(/.+\..+/)
IPV4_REGEX = Regexp.new(/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/)
IPV6_REGEX = Regexp.new(/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/)
PRIVATE_RANGES = %w[127.0.0.0/8 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 100.64