Skip to content

Instantly share code, notes, and snippets.

@kgilpin
kgilpin / sequenceDiagram.js
Created March 3, 2023 14:08
Read diagram data from a ZIP file
const params = new URL(document.location).searchParams;
const diagramUrl = params.get('diagram');
let diagramData;
if (diagramUrl.endsWith('.zip')) {
const resourceId = params.get('resourceId');
if (!resourceId) throw new Error(`resourceId is required with diagram resource ZIP file`);
const localStorageKey = ['appmap', 'diagram', diagramUrl].join('-');
let diagramDataEncoded;
if (!['false', 'no'].includes(params.get('cache')))
@kgilpin
kgilpin / Following_followers_page.appmap.json
Created November 29, 2022 18:55
Example files from blog post "Generate sequence diagrams from runtime code analysis"
{
"events": [
{
"id": 1,
"event": "call",
"thread_id": 4280,
"defined_class": "ActionDispatch::Integration::Runner",
"method_id": "before_setup",
"path": "/Users/kgilpin/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/actionpack-6.0.4.1/lib/action_dispatch/testing/integration.rb",
"lineno": 320,
@kgilpin
kgilpin / appmap.rake
Created November 29, 2022 16:19
Rake task to detect untested routes
# Sort by path, then by method
compare_routes = lambda do |a,b|
compare = a[1] <=> b[1]
compare = a[0] <=> b[0] if compare == 0
compare
end
normalize_method = lambda do |method|
method = method.upcase
# For Rails, HEAD request is served by 'show' (GET)
@kgilpin
kgilpin / pre_request.js
Last active July 14, 2022 16:59
Rails Sample App 6th Ed Postman Pre-request script
pm.sendRequest(pm.variables.get('baseUrl'), function (err, response) {
const token = /meta\s+name="csrf-token"\s+content="(.*)"/.exec(response.text());
console.log(`CSRF protection: ${token}`);
if( token) {
pm.globals.set('authenticity_token', token[1]);
}
})
@kgilpin
kgilpin / head_sql.yml
Last active July 13, 2021 15:40
Example files - Preventing data leaks with runtime code analysis
- DELETE FROM "ahoy_messages" WHERE "ahoy_messages"."user_id" = $?
- DELETE FROM "api_secrets" WHERE "api_secrets"."id" = $?
- DELETE FROM "api_secrets" WHERE "api_secrets"."user_id" = $?
- DELETE FROM "articles" WHERE "articles"."id" = $?
- DELETE FROM "badge_achievements" WHERE "badge_achievements"."id" = $?
- DELETE FROM "badge_achievements" WHERE "badge_achievements"."user_id" = $?
- DELETE FROM "broadcasts" WHERE "broadcasts"."id" = $?
- >-
DELETE FROM "chat_channel_memberships" WHERE "chat_channel_memberships"."id"
= $?
{
"$schema": "https://aka.ms/codetour-schema",
"title": "Install AppMap for RSpec",
"steps": [
{
"file": "spec/spec_helper.rb",
"description": "You'll now install the AppMap RSpec helper.\n\n```ruby\nrequire 'appmap/rspec'\n```\n\nThis line should be placed **before** any other `require` statements.\n",
"line": 2,
"contents": "require 'appmap/rspec'"
},
@kgilpin
kgilpin / main.py
Last active March 2, 2021 17:54
SSH connection from Python
import sys
import os
import appmap
#start the recorder
r = appmap.Recording()
with r:
#run the SSH demo code
import sshdemo
sshdemo.Demo().runDemo()
@kgilpin
kgilpin / appmap.yml
Created February 12, 2021 14:56
appmap.yml for Rails Sample App 6th Edition
name: sample_app_6th_ed
packages:
- path: app/mailers
- path: app/models
- path: app/jobs
- path: app/controllers
- path: app/helpers
- gem: actioncable
- gem: actionmailbox
- gem: actionmailer
@kgilpin
kgilpin / README.md
Last active February 10, 2021 21:11
VSCode project with Rails gem paths

Usage

  1. Save rails_gem_paths.rb to your local directory

  2. Run this command to open a VSCode project containing the local directory and all "active*" and "action*" gems. The script also prints out the gem names in appmap.yml form.

code . $(bundle exec ruby rails_gem_paths.rb)
# - gem: actioncable
# - gem: actionmailbox