Skip to content

Instantly share code, notes, and snippets.

@tgmerritt
tgmerritt / fizzbuzz_one_line.rb
Created August 19, 2015 14:30
FizzBuzz One Line in Ruby - which is fastest?
#!/bin/ruby
require "benchmark"
iterations = 100_000
Benchmark.bm do |bm|
bm.report do
iterations.times do
(1..100).each{|i| (str = (i%3!=0 ? '':"Fizz")+(i%5!=0 ? '':"Buzz")).empty? ? i : str}
end
@tgmerritt
tgmerritt / watermark_with_image.rb
Created September 25, 2017 21:03 — forked from adityashedge/watermark_with_image.rb
Watermark images with ImageMagick 'convert' using 'composite', 'watermark' and 'dissolve' in Ruby
# Watermarking image with another image using Imagemagick 'composite', 'watermark' and 'dissolve'.
require "rubygems"
require "RMagick"
require "pry"
include Magick
# Read the image in the memory with RMagick
puts "What is the image file you want to watermark?"
puts "Drag and drop the file here or enter the full path to the image"
path = gets.chomp
@tgmerritt
tgmerritt / mutual_fund_info.rb
Created November 29, 2017 17:04
Mutual Fund Sector Weights without an API
#!/usr/bin/env ruby
require 'mechanize'
require 'csv'
tickers = ["EWX","EZM","FMIJX","IGM","IGV","ITOT","POGRX","PRHSX","SCZ","SPEM","SPVU","SYE","VEA","XSLV","TRBIX","VEMIX","VIIIX","VWILX","VSCIX"]
mechanize = Mechanize.new
puts "Creating new CSV"
@tgmerritt
tgmerritt / gist:d654510f16f3d41a0c06384ef67935e4
Created May 17, 2018 23:05
CAN messages from Lexus RX Hybrid 2017
CAN 0
0414(1044)( 24) 0000000000001700
0420(1056)( 145) 0002000cfbfc0031
0423(1059)( 142) 00
0427(1063)( 145) 0000000000000000
042F(1071)( 143) 0000000000000000
0435(1077)( 144) 850505ffe00f0003
045A(1114)( 142) 5a04006400000000
0489(1161)( 23) 0000000000000004
@tgmerritt
tgmerritt / houndify.py
Created August 23, 2019 18:34
Houndify API in Ruby and original source in Python
##############################################################################
# Copyright 2019 SoundHound, Incorporated. All rights reserved.
##############################################################################
import base64
import hashlib
import hmac
import http.client
import json
import threading
import time
@tgmerritt
tgmerritt / 01_elastic_beanstalk_install_packages.config
Created February 11, 2020 18:49 — forked from hanhdt/01_elastic_beanstalk_install_packages.config
Setup additional linux packages on AWS Elastic Beanstalk that need to build Rails 5
# Setup linux packages
option_settings:
- option_name: BUNDLE_DISABLE_SHARED_GEMS
value: "1"
- option_name: BUNDLE_PATH
value: "vendor/bundle"
packages:
yum:
curl: []
@tgmerritt
tgmerritt / AWS_Single_LetsEncrypt.yaml
Created February 13, 2020 22:07 — forked from tony-gutierrez/AWS_Single_LetsEncrypt.yaml
AWS Elastic Beanstalk .ebextensions config for single instance free SSL using letsencrypt certbot and nginx. http://bluefletch.com/blog/domain-agnostic-letsencrypt-ssl-config-for-elastic-beanstalk-single-instances/
# Dont forget to set the env variable "certdomain", and either fill in your email below or use an env variable for that too.
# Also note that this config is using the LetsEncrypt staging server, remove the flag when ready!
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
@tgmerritt
tgmerritt / 01_nginx.config
Created February 19, 2020 02:00 — forked from luisacarrion/01_nginx.config
AWS Elastic Beanstalk .ebextensions - get S3 file with commands key
commands:
01_get_nginx_conf_file:
command: aws s3 cp s3://your-bucket-name/shared_config/an_nginx_http.conf /home/ec2-user
container_commands:
01_move_nginx_conf_file:
command: mv -f /home/ec2-user/an_nginx_http.conf /etc/nginx/conf.d/an_nginx_http.conf
02_reload_nginx:
command: "sudo service nginx reload"
@tgmerritt
tgmerritt / gist:d87ec15daf18df698f972fc2dcb92c28
Created July 27, 2022 20:25
Delete all node_modules directories in all projects

List all node_modules and the cumulative size (Mac OS / Linux)

find . -name "node_modules" -type d -prune | xargs du -chs

Destroy all

find . -name "node_modules" -type d -prune -exec rm -rf '{}' +