Skip to content

Instantly share code, notes, and snippets.

View dpaluy's full-sized avatar

David Paluy dpaluy

  • Majestic Labs
  • Austin, TX
  • X @dpaluy
View GitHub Profile
@dpaluy
dpaluy / dynamic_debug.rb
Last active September 29, 2016 19:58
Dynamic Ruby Debugging
# Source: http://blog.iempire.ru/2016/09/23/breaking-points/
#
mod = Module.new do
def add(*args)
binding.pry
super
end
end
credit_card.errors.extend(mod)
function increaseCounter() {
var account = web3.eth.accounts[0];
var currentNumber = contract_instance.getMyNumber().toNumber();
currentNumber++;
// User dialog goes here
web3.personal.unlockAccount(account, 'secretpasswrod');
contract_instance.setMyNumber(currentNumber, {from: account, gas: 200000}, function(error, result) {
if (error) {
@dpaluy
dpaluy / Escrow-Smart-Contract
Created March 15, 2018 14:13 — forked from ToJen/Escrow-Smart-Contract
Example of an escrow smart contract
// package.json
{
"dependencies": {
"web3": "0.20.0",
"solc": "^0.4.19"
}
}
//Create file Ecrow.sol and create 3 variables: a buyer, a seller, and an arbiter
contract Escrow {
@dpaluy
dpaluy / MAC_Setup.md
Last active April 1, 2022 21:03
Mac Setup - Generic
@dpaluy
dpaluy / rack_attack.rb
Created June 28, 2018 20:01
ignore PHP bots
class Rack::Attack
Rack::Attack.blocklist('bad-robots') do |req|
req.ip if /\S+\.php/.match?(req.path)
end
end if Rail.env.production?
@dpaluy
dpaluy / my_controller_spec.rb
Last active December 2, 2018 06:41
Bullet in RSpec
# spec/controllers/my_controller_spec.rb
context 'N+1' do
bulletify { get :index }
end
@dpaluy
dpaluy / fixture_helpers.rb
Created December 2, 2018 06:47
RSpec Helpers
# spec/support/fixture_helpers.rb
def fixture_file_path(filename)
Rails.root.join("spec/fixtures/#{filename}").to_s
end
def read_fixture_file(filename)
File.read fixture_file_path(filename)
end
@dpaluy
dpaluy / sidekiq_mediator.rb
Created December 8, 2018 08:26
Passing current_user to Sidekiq
module SidekiqMediator
def perform_async(klass, *args)
args.push(current_user.login)
klass.send(:perform_async, *args)
end
end
# EXAMPLE
class DeliveryController < ApplicationController
@dpaluy
dpaluy / active_admin_cheats.rb
Last active June 22, 2019 10:12 — forked from codespore/Active_Admin_Cheats.rb
Quick reference to useful ActiveAdmin customizations
# Add Action button on the top navigation menu. Useful for resource with nested resources
action_item :only => :show do
link_to('Show Users', admin_group_users_path(resource))
end
# Custom show page with children items
show do
@dpaluy
dpaluy / analytics.js
Last active July 27, 2022 03:00
Frontend Analytics
// Google Analytics
class GoogleAnalytics {
constructor() {
this.ga = typeof window.ga === 'function' ? window.ga : () => null;
}
pageView = (params) => {
setTimeout(() => this.ga('send', params, window.location.pathname));
}
event = (params) => {