Skip to content

Instantly share code, notes, and snippets.

@mtancoigne
mtancoigne / airsec.rb
Created February 27, 2023 09:52
Find outdated gems in sub-directories
#!/usr/bin/env ruby
# frozen_string_literal: true
# Find projects with outdated dependencies
#
# Usage:
# airsec <gem>
# airsec <gem> [[min version] max version]
#
@mtancoigne
mtancoigne / git-bs
Last active February 28, 2023 10:16
Display statuses of local git branches
#!/usr/bin/env ruby
# frozen_string_literal: true
# Display branch statuses
#
# @author Manuel Tancoigne <m.tancoigne@experimentslabs.com>
# @license MIT
# @version 0.2.3
#
# Requirements
@guich-wo
guich-wo / highlight-ruby.applescript
Created February 14, 2018 13:06
Applescript to highlight ruby code in Pages
# Applescript to highlight ruby code in Pages
# Requirements : Pygments (http://pygments.org/languages/) : pip install Pygments
# Tutorial: https://shomeya.com/articles/screencast-how-to-add-syntax-highlighting-to-pages-and-keynote
try
set old to the clipboard as record
end try
tell application "System Events" to keystroke "c" using command down
do shell script "export LC_CTYPE=UTF-8; pbpaste | /usr/local/bin/pygmentize -l ruby -f rtf -O style=default | pbcopy -Prefer rtf"
tell application "System Events" to keystroke "v" using command down
delay 0.05
@acundari
acundari / traefik-auth.conf
Last active December 6, 2022 09:41
Traefik fail2ban
# /etc/fail2ban/filter.d/traefik-auth.conf
[Definition]
failregex = ^<HOST> \- \S+ \[\] \"(GET|POST|HEAD) .+\" 401 .+$
@davidderus
davidderus / application_policy.rb
Last active October 26, 2016 11:47
Non-Standard ApplicationPolicy for Pundit
# Handling Application rights thanks to roles
#
# A direct adaptation of http://through-voidness.blogspot.fr/2013/10/advanced-rails-4-authorization-with.html
# but much more performance-wise
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
raise Pundit::NotAuthorizedError, 'Must be signed in.' unless user
@user = user
@mrrooijen
mrrooijen / database.sslmode.require.yml
Last active February 6, 2024 21:33
SSL configurations for Rails + Postgres in either require or verify-full mode to ensure secure connections. Useful for Amazon RDS, Compose.io, etc.
production:
adapter: postgresql
encoding: unicode
sslmode: require
url: postgres://user:password@host:port/db
@oeN
oeN / weighted.rb
Last active April 29, 2020 19:34
Shuffle a Weighted array in Ruby
def weighted
a = []
(1..60).each do |i|
a << { value: "HIGH_#{i}", weight: 5 }
end
(1..30).each do |i|
a << { value: "MID_#{i}", weight: 3 }
end
(1..15).each do |i|
a << { value: "LOW_#{i}", weight: 2 }
@paulirish
paulirish / how-to-view-source-of-chrome-extension.md
Last active April 25, 2024 04:16
How to view-source of a Chrome extension

Option 1: Command-line download extension as zip and extract

extension_id=jifpbeccnghkjeaalbbjmodiffmgedin   # change this ID
curl -L -o "$extension_id.zip" "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=stable&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc" 
unzip -d "$extension_id-source" "$extension_id.zip"

Thx to crxviewer for the magic download URL.

@rainyear
rainyear / handy.py
Created July 3, 2015 10:09
Hand posture detection with OpenCV.
#!/usr/bin/env python
import cv2
import numpy as np
def main():
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
ret, img = cap.read()
skinMask = HSVBin(img)
@50kudos
50kudos / flashflush.sh
Last active November 3, 2019 02:03
A Bash script that lists all unused css classes in html/haml/erb files for rails project (or maybe others depending on project structure)
#!/bin/bash
cat $(find app/assets/stylesheets/ -type f) |
grep -Eo '\.[a-z]+[a-z0-9_-]*' | sort | uniq | sed s/.// |
while read CSS; do
if ! grep -Erqi "([^(remove|has)]?class[(:|=|[:space:]*=>[:space:]*)]*[[:space:]\W]*[(\"|')]*[-a-z0-9[:space:]]*$CSS|\\.$CSS\b)" app/views/ vendor/assets/ app/assets/javascripts/; then
echo $CSS >> unused.scss;
fi
done