Skip to content

Instantly share code, notes, and snippets.

View subelsky's full-sized avatar
🧘‍♂️

Mike Subelsky subelsky

🧘‍♂️
View GitHub Profile
@subelsky
subelsky / contracts...FleetwoodToken.sol
Created April 1, 2022 21:50
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.7;
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
//
// ----------------------------------------------------------------------------
abstract contract ERC20Interface {
function totalSupply() virtual public view returns (uint);
function balanceOf(address tokenOwner) virtual public view returns (uint balance);
@subelsky
subelsky / casperjs_example.js
Created August 8, 2012 18:51
Webscraping with CasperJS, PhantomJS, jQuery, and XPath
var system = require('system');
if (system.args.length < 5) {
console.info("You need to pass in account name, username, password, and path to casperJS as arguments to this code.");
phantom.exit();
}
var account = system.args[1];
var username = system.args[2];
var password = system.args[3];
@subelsky
subelsky / puma_rails_heroku.rb
Created October 31, 2012 13:51
Setting up Puma and Rails on Heroku
# Gemfile
gem "puma"
# Procfile
web: bundle exec puma -p $PORT -e $RACK_ENV -C config/puma.rb
# add to config block config/environments/production.rb
config.threadsafe!
# get rid of NewRelic after_fork code, if you were doing this:
@subelsky
subelsky / threading_and_forking.rb
Last active June 17, 2020 14:34
Ruby Threading & Forking Demo
#!/usr/bin/env ruby
# STAQ threading & forking training 4/26/16
#
# Invoke like so:
#
# ruby forking_and_threading.rb
# ruby forking_and_threading.rb thread
# ruby forking_and_threading.rb naive # seems to work OK
# env RBENV_VERSION=jruby-9.0.4.0 ruby ./forking_and_threading.rb naive # why does this give different results?
#
@subelsky
subelsky / large_redshift_tables.sql
Created April 18, 2014 17:39
Quick SQL command to find large tables in redshift
-- based on http://stackoverflow.com/questions/21767780/how-to-find-size-of-database-schema-table-in-redshift
SELECT name AS table_name, ROUND((COUNT(*) / 1024.0),2) as "Size in Gigabytes"
FROM stv_blocklist
INNER JOIN
(SELECT DISTINCT id, name FROM stv_tbl_perm) names
ON names.id = stv_blocklist.tbl
GROUP BY name
ORDER BY "Size in Gigabytes" DESC
@subelsky
subelsky / aliases.sh
Created October 17, 2013 14:05
Useful aliases for Ruby and Rails development and git maintenance
alias a='ack'
alias a?='alias | grep -i'
alias adx='rake db:drop && rake db:create && heroku pg:transfer --from black --to postgres://postgres@localhost/staq_development --confirm staqweb --app staqweb && rails r "User.all.each { |u| u.update_attribute(:password,%q(password)) }" && rake db:test:prepare'
alias b='bundle'
alias bb='bundle install --binstubs=.bundle/bin --path=.bundle/gems && bundle package --all && reload ; sd'
alias bc='bin/console'
alias be='bundle exec'
alias bea='bundle exec annotate'
alias bu='bundle update'
alias bus='bundle update staq_extraction'
@subelsky
subelsky / asset.rake
Created March 3, 2013 21:48
Quick rake task to check if assets need to pre-compiled before deployment (since I don't like precompiling during deployment)
namespace :assets do
task :check do
root_dir = File.join(File.dirname(__FILE__),"..","..")
assets_last_modified_at = Dir["#{root_dir}/app/assets/**/**"].map { |p| File.mtime(p) }.sort.last
assets_last_compiled_at = Dir["#{root_dir}/public/assets/**/**"].map { |p| File.mtime(p) }.sort.last
if assets_last_modified_at > assets_last_compiled_at
fail "Assets need to precompiled; last asset modified at #{assets_last_modified_at}"
end
end
@subelsky
subelsky / .railsrc
Last active May 3, 2017 17:31
How to make activerecord log SQL to the console
# makes Rails logs appear in the console, useful for seeing the actual SQL query generated from an AR find for example
# put this in ~/.railsrc
require 'logger'
Rails.logger = Logger.new STDOUT
# There's not much documentation about nifi's JRuby API but it closely follows
# what the python API looks like:
# see http://funnifi.blogspot.com/2016/02/executescript-processor-hello-world.html
flow_file = session.get()
updated_flow_file = session.putAttribute(flow_file,"my-attribute","my-value")
session.transfer(updated_flow_file,REL_SUCCESS)
@subelsky
subelsky / move_github_repos.sh
Created April 10, 2012 16:30
How to archive old github private projects on Dropbox
# http://stackoverflow.com/questions/1960799/using-gitdropbox-together-effectively/1961515#1961515
export REPONAME=????
take ~/Dropbox/git/$REPONAME.git
git init --bare
cd ~/code/$REPONAME
git remote rm origin
git remote add origin ~/Dropbox/git/$REPONAME.git
git push -u origin master