Skip to content

Instantly share code, notes, and snippets.

@jugyo
jugyo / request_logger.rb
Last active November 16, 2023 17:25
Rack middleware for logging all rails request
# Add below into config/application.rb:
#
# config.middleware.use 'RequestLogger'
#
class RequestLogger
def initialize app
@app = app
end
def call(env)
@mbrownnycnyc
mbrownnycnyc / android_apk_cert_pinning_mitm.txt
Last active March 18, 2023 03:32
Android APK cert pinning removal and MiTM - focusing on Sense Home Energy Monitor APK
https://dl.google.com/android/repository/tools_r25.2.3-windows.zip
https://medium.com/@felipecsl/bypassing-certificate-pinning-on-android-for-fun-and-profit-1b0d14beab2b#.pnph846be
http://www.security-assessment.com/files/documents/whitepapers/Bypassing%20SSL%20Pinning%20on%20Android%20via%20Reverse%20Engineering.pdf
https://stackoverflow.com/questions/64364407/app-not-installing-in-android-11-but-works-on-previous-versions
1) download apktool and the build tools (http://androidsdkoffline.blogspot.com/p/android-sdk-build-tools.html) and platform tools (https://developer.android.com/studio/releases/platform-tools.html)
"C:\Users\mbrown\Desktop\Sense APK\apktool" d base.apk
@rambabusaravanan
rambabusaravanan / .gitconfig
Last active April 30, 2024 04:40
Git Diff and Merge Tool - IntelliJ IDEA
# Linux
# add the following to "~/.gitconfig" file
[merge]
tool = intellij
[mergetool "intellij"]
cmd = /usr/local/bin/idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
trustExitCode = true
[diff]
def session_data(request)
session_key = Rails.application.config.session_options[:key]
request
.cookie_jar
.signed_or_encrypted[session_key] || {}
end
session_id = lambda do |request|
session_data(request)["session_id"] || "no session"
end
@rob-murray
rob-murray / find_dups.rb
Created October 27, 2015 09:59
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)
@morhekil
morhekil / anonsplat.rb
Created June 23, 2015 23:20
Destructuring Ruby hashes with named parameters and anonymous splat
def stuff
yield action: 'Boom', schedule: '7PM', color: :red, debug: true
end
# When a hash is yielded to a block, we can used named arguments to
# capture the keys we want, and an anonymous splat to ignore
# everything else
stuff { |action:, schedule:, **| p "Doing #{action} at #{schedule}" }
#
@thom-nic
thom-nic / chunked_transfer_decoder.rb
Last active February 5, 2020 15:23
Rack middleware to decode chunked transfer HTTP request
#require 'rack/request'
# Rack middleware to decode a `Transfer-Encoding: chunked` HTTP request.
#
# USAGE NOTE:
#
# Some HTTP servers (Webrick and Unicorn/Rabinbows/Zbatery) already decode the
# chunked stream, but they leave the 'Transfer-Encoding' header and don't bother
# to add a 'Content-Length' header, which causes rails ActionDispatch::Request
# to not parse the whole request body.
@damien-roche
damien-roche / rubymethodlookup.md
Last active January 16, 2024 10:40
A Primer on Ruby Method Lookup

A Primer on Ruby Method Lookup

Method lookup is a simple affair in most languages without multiple inheritance. You start from the receiver and move up the ancestors chain until you locate the method. Because Ruby allows you to mix in modules and extend singleton classes at runtime, this is an entirely different affair.

I will not build contrived code to exemplify the more complicated aspects of Ruby method lookup, as this will only serve to confuse the matter.

When you pass a message to an object, here is how Ruby finds what method to call:

1. Look within singleton class

require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@ccschmitz
ccschmitz / data_migrations_in_rails.md
Created August 19, 2014 13:10
Some tips for handling data migrations in Rails

Data Migrations in Rails Apps

If you need to manipulate existing data when your code is deployed, there are two main ways to do it:

  1. Create a rake task to migrate the data after the code is deployed. This is ideal for more complex data migrations.
  2. Use ActiveRecord models in a migration. This is acceptable for smaller data manipulations.

Regardless of the method you use, make sure to test your migrations before submitting them.

Data Migrations in Models