Skip to content

Instantly share code, notes, and snippets.

View cjavdev's full-sized avatar
👉

CJ Avilla cjavdev

👉
View GitHub Profile
@cjavdev
cjavdev / xsolla_webhooks.py
Created June 16, 2025 12:07
XSolla Webhook Example
@app.route('/webhooks', methods=['POST'])
def xsolla_webhook():
# Get the signature from headers
signature = request.headers.get('Authorization')
# Get the raw request body as a string:
payload = request.data.decode('utf-8')
payload_with_key = "%s%s" % (payload, XSOLLA_WH_KEY)
# Verify the webhook signature if provided
{
"data": [
{
"readingId": "fuelLevel",
"entityId": "123456",
"entityType": "sensor",
"value": {
"fuelLevelLiters": 47.0,
"fuelLevelGallons": 12.4161,
},
@cjavdev
cjavdev / keybindings.json
Last active September 5, 2024 13:42
hjlk vim nav and test runner in vs code
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+e",
"command": "-extension.vim_ctrl+e",
"when": "editorTextFocus && vim.active && vim.use<C-e> && !inDebugRepl"
},
{
"key": "ctrl+a",
"command": "-extension.vim_ctrl+a",
@cjavdev
cjavdev / test.rb
Created August 27, 2024 13:48
Rails 7.2 ApplicationSystemTestCase missing host
# config/environments/test.rb
# ...
# Already had this:
config.action_mailer.default_url_options = { host: "www.example.com" }
# Had to add this:
Rails.application.routes.default_url_options = { host: "www.example.com" }
rails r 'require "redis"; redis = Redis.new; pattern = "jbuilder/*"; cursor = 0; loop do;cursor, keys = redis.scan(cursor, match: pattern);redis.del(*keys) unless keys.empty?;break if cursor == "0";end;'
@cjavdev
cjavdev / dump.rake
Created October 5, 2023 13:17
Handy little rake task for dumping prod db locally then redacting
namespace :dump do
task db: :environment do
if !Rails.env.development?
raise "This task is only available in development environment"
end
puts "Removing potential existing backups..."
if File.directory?("/tmp/backups")
FileUtils.rm_rf("/tmp/backups")
end
ActiveRecord::Base.connection.execute(<<-SQL)
UPDATE projects
SET comments_count = (
SELECT COUNT(*)
FROM comments
WHERE comments.commentable_id = projects.id
AND comments.commentable_type = 'Project'
)
SQL
// TODO: Make typescript happy here.
type JSONValue =
| string
| number
| boolean
| { [x: string]: JSONValue }
| Array<JSONValue>;
interface JSONObject {
[x: string]: JSONValue;
if ARGV.empty?
data = DATA.readlines(chomp: true)
else
data = File.readlines(ARGV[0], chomp: true)
end
solved = {}
expressions = {}
data.each do |line|