Skip to content

Instantly share code, notes, and snippets.

@humphreyja
humphreyja / active_admin.rb
Created November 13, 2019 19:58
Include react components into active admin using React On Rails.
# config/initializers/active_admin.rb
#...
module ActiveAdmin
module Views
# Defines a `react_component` active admin component. It allows you
# to include react components into active admin using React On Rails.
# Example:
#
@blha303
blha303 / compliment.b303.me.py
Last active June 25, 2021 04:41
Gets random comment from /r/gonewild, since they're pretty much all compliments. http://compliment.b303.me Warning: May contain sexual content
#!/usr/bin/env python3
import requests
from flask import *
import random
from apscheduler.schedulers.background import BackgroundScheduler
app = Flask(__name__)
scheduler = BackgroundScheduler()
url = "https://reddit.com/r/gonewild/comments.json?limit=200"
@Joncom
Joncom / gist:e8e8d18ebe7fe55c3894
Last active September 11, 2021 00:29
Check if two line segments intersect
// Adapted from: http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect/1968345#1968345
function line_intersects(p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y) {
var s1_x, s1_y, s2_x, s2_y;
s1_x = p1_x - p0_x;
s1_y = p1_y - p0_y;
s2_x = p3_x - p2_x;
s2_y = p3_y - p2_y;
var s, t;
@taf2
taf2 / reconnect-on-disconnect.js
Created July 1, 2011 15:51
mongoose node.js reconnect code
var mongoose = require('mongoose');
var db = mongoose.connect("mongodb://localhost/testdb");
var reconnTimer = null;
function tryReconnect() {
reconnTimer = null;
console.log("try to connect: %d", mongoose.connection.readyState);
db = mongoose.connect("mongodb://localhost/testdb");
}
@danneu
danneu / benchmark
Created October 29, 2012 23:04
Ox vs Nokogiri: DOM and SAX parsing comparison
# I'm no benchmark guru. Just did a bunch of:
$ time ruby <filename>
# Note: This is just an 80mb XML file with 38,000 nodes.
ox_dom.rb 4.56s user 0.78s system 93% cpu 5.714 total (550mb)
ox_dom.rb 4.58s user 0.79s system 87% cpu 6.126 total (550mb)
ox_dom.rb 4.60s user 0.80s system 87% cpu 6.140 total (550mb)
nokigiri_dom.rb 11.75s user 1.02s system 94% cpu 13.518 total (895mb)
nokigiri_dom.rb 11.36s user 1.02s system 93% cpu 13.211 total (895mb)
@u1-liquid
u1-liquid / update-sentry.sh
Last active March 23, 2022 15:01
Update Sentry on Docker
#!/bin/sh
sudo docker stop sentry-worker sentry-cron
sudo docker stop sentry sentry-smtp sentry-postgres sentry-redis
sudo docker rm sentry-worker
sudo docker rm sentry-cron
sudo docker rm sentry
sudo docker rm sentry-smtp
sudo docker rm sentry-postgres
@ninoseki
ninoseki / test.rb
Created December 12, 2018 02:37
Playing with wss://certstream.calidog.io in Ruby
require 'faye/websocket'
require 'eventmachine'
require "json"
EM.run {
ws = Faye::WebSocket::Client.new("wss://certstream.calidog.io")
ws.on :message do |event|
message = JSON.parse(event.data)
all_domains = message.dig("data", "leaf_cert", "all_domains")
@derrek
derrek / google_play_receipt_verification.md
Last active August 17, 2022 19:34
Google Play/Android Receipt Validation/Verification/Lookup with Ruby

This document outlines setting up google's ruby gem, google-api-client, to verify payloads(receipts) sent to a server from google play in app purchases made via an android app.
This document was written using version 0.9.13.

First you'll need 'owner' access to the google play developer's console that contains the mobile app you wish to verify receipts from.

  • Go to https://play.google.com/apps/publish
  • Click on the mobile app you'd like to set up
  • Click "Settings" on the left click "API access"
  • Below "LINKED PROJECT" link the google play account

Next setup an api account

@bruth
bruth / README.md
Last active November 23, 2022 21:54
Postgres push notification

Postgres push triggers

Watch a table for changes and push a notification with a payload describing the change.

Example

In the Postgres shell:

-- Create the functions
@DSKonstantin
DSKonstantin / Auto start puma via systemctl description
Last active November 16, 2023 16:14
Auto start puma via systemctl
Article: https://github.com/puma/puma/blob/master/docs/systemd.md
#1 nano /etc/systemd/system/puma.service
#2 paste from puma.service
Commands:
# After installing or making changes to puma.service
systemctl daemon-reload
# Enable so it starts on boot
systemctl enable puma.service