Skip to content

Instantly share code, notes, and snippets.

View krtschmr's full-sized avatar
🏠
Creating the future

Tim Kretschmer krtschmr

🏠
Creating the future
  • Amsterdam, Netherlands
  • 09:33 (UTC +02:00)
View GitHub Profile
@mabenson00
mabenson00 / cheatsheet.rb
Last active May 3, 2024 22:40
Rails ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@anacampesan
anacampesan / copyToClipboard.html
Last active May 20, 2021 10:41
Copy to clipboard without input
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="secretInfo" style="display: none;">secret info</div>
<button type="button" id="btnCopy">Copy hidden info</button>
@treble37
treble37 / gist:55459f5f0f218ab9b5ebe74b325f4a41
Created May 16, 2017 18:19
Ruby AES Encryption using OpenSSL
#!/usr/bin/env ruby
require "openssl"
require 'digest/sha2'
require 'base64'
# We use the AES 256 bit cipher-block chaining symetric encryption
alg = "AES-256-CBC"
# We want a 256 bit key symetric key based on some passphrase
digest = Digest::SHA256.new
@krtschmr
krtschmr / need_admin_approval.rb
Last active October 4, 2019 08:27
Extension for ActiveRecord to make any changes for an objects attributes protected and create a seperate ChangeRequest which needs to be approved
# usage
# your model
# need_admin_approval fields: [:name, :description], if: :published?, unless: :trusted_user?
module NeedAdminApproval
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
@denmarkin
denmarkin / resque.rake
Created September 20, 2011 11:02
My rake task for clearing Resque queues and stats
# see http://stackoverflow.com/questions/5880962/how-to-destroy-jobs-enqueued-by-resque-workers - old version
# see https://github.com/defunkt/resque/issues/49
# see http://redis.io/commands - new commands
namespace :resque do
desc "Clear pending tasks"
task :clear => :environment do
queues = Resque.queues
queues.each do |queue_name|
puts "Clearing #{queue_name}..."