Skip to content

Instantly share code, notes, and snippets.

@fraune
fraune / touch_id_sudo.sh
Last active December 13, 2024 02:19
Let Touch ID authorize the `sudo` terminal command in macOS 14+
sudo sh -c 'echo "auth sufficient pam_tid.so" > /etc/pam.d/sudo_local'
@kodekracker
kodekracker / pseudo_enc_bigint.sql
Created September 19, 2020 16:49 — forked from dariushoule/pseudo_enc_bigint.sql
bigint feistel pseudo encrypt
CREATE OR REPLACE FUNCTION pseudo_encrypt(VALUE bigint) returns bigint AS $$
DECLARE
l1 bigint;
l2 bigint;
r1 bigint;
r2 bigint;
i int:=0;
BEGIN
l1:= (VALUE >> 32) & 4294967295::bigint;
r1:= VALUE & 4294967295;
@fnky
fnky / stripe-keys-and-ids.tsv
Last active March 30, 2025 17:52
Stripe keys and IDs
Prefix Description Notes
ac_ Platform Client ID Identifier for an auth code/client id.
acct_ Account ID Identifier for an Account object.
aliacc_ Alipay Account ID Identifier for an Alipay account.
ba_ Bank Account ID Identifier for a Bank Account object.
btok_ Bank Token ID Identifier for a Bank Token object.
card_ Card ID Identifier for a Card object.
cbtxn_ Customer Balance Transaction ID Identifier for a Customer Balance Transaction object.
ch_ Charge ID Identifier for a Charge object.
cn_ Credit Note ID Identifier for a Credit Note object.
@blueset
blueset / README.md
Last active May 14, 2019 15:49
Filter all telegram stickers messages in groups for 60 seconds.
  1. Clone https://github.com/vysheng/tg/, and install all necessary dependencies
  2. Apply documents.patch, then ./configure && make
  3. pip3 install pytg
  4. Modify main.py and change tgdir to the correct path.
  5. Log in your tg-cli
  6. nohup ./bin/telegram-cli --json -R -W -P 4458 --permanent-peer-ids --permanent-peer-ids > /dev/null &
  7. nohup python3 kagami.py > /dev/null &
@josiahcarlson
josiahcarlson / rate_limit2.py
Last active April 17, 2022 09:22
Regular and sliding window rate limiting to accompany two blog posts.
'''
rate_limit2.py
Copyright 2014, Josiah Carlson - [email protected]
Released under the MIT license
This module intends to show how to perform standard and sliding-window rate
limits as a companion to the two articles posted on Binpress entitled
"Introduction to rate limiting with Redis", parts 1 and 2:
@dmitry
dmitry / paper_trail.rb
Created May 21, 2014 22:43
Include paper_trail for all the models.
ActiveRecord::Base.module_eval do
class << self
def inherited_with_paper_trail(subclass)
skip_models = %w(schema_migrations versions)
inherited_without_paper_trail(subclass)
table_name = subclass.table_name
if !skip_models.include?(table_name) && table_name.present?
@justinweiss
justinweiss / filterable.rb
Last active January 30, 2025 13:06
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
@krisf
krisf / enc
Last active June 4, 2024 12:17
decrypts OpenSSL encrypted files from ruby Backup gem
#!/bin/bash
#encrypt files with aes-256-cbc cipher using openssl
#install:
# sudo wget -O /usr/bin/enc https://gist.github.com/krisf/5391210/raw/4a105a6b8f98f39e9e74a1dd2a78ef6f631acdb1/enc
# sudo chmod +x /usr/bin/enc
# enc --help
#encrypt files
if [ $1 == "-e" ];
then
upstream some_app_server {
server 127.0.0.1:9393;
}
server {
listen 80;
server_name my-upload-endpoint.com ;

Devise / Warden Tagged logging

I wrote a middleware (actually two, but they do the same with different implementations) that logs information about signed in scopes in a Rails + Devise application. The solution works with multiple logins (like having a person logged both as an Admin and a User). I tested against Rails 4 and Devise HEAD, but it should work fine in any Rails 3 application.

This solution doesn't use the log_tags configuration option since it isn't very helpful when you need to retrieve information stored in cookies/session. That information isn't 'ready' when the Rails::Rack::Logger is executed, since it happens way down in the middleware chain.

Add one of the following implementations to your application load path and use the following configuration to add the middleware to your application stack:

# application.rb