Skip to content

Instantly share code, notes, and snippets.

🎮

Edgar Ortega EdgarOrtegaRamirez

View GitHub Profile
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / append_gzip.rb
Last active Dec 6, 2018
Ruby - Append to a gzip CSV file
View append_gzip.rb
require "zlib"
open_mode = "ab" # append / binary
file = File.open('path-to-file.csv.gz', open_mode)
gz = Zlib::GzipWriter.new(file)
gz.write("new,row,csv\n")
gz.close
# http://ruby-doc.org/core-2.5.3/IO.html#method-c-new
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / install.sh
Created Jul 13, 2018
Install SQLite3 in Linux from source code (amalgamation)
View install.sh
wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
tar xvfz sqlite-autoconf-3240000.tar.gz
cd sqlite-autoconf-3240000
./configure
make
make install # you may need sudo
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / file_downloader.rb
Last active Jul 6, 2018
Simple File Downloader in Ruby using Net::HTTP, it downloads by chuncks into a file to keep memory as low as possible
View file_downloader.rb
# frozen_string_literal: true
require "net/http"
class FileDownloader
attr_reader :uri, :http_response
HTTPS_SCHEME = "https"
def initialize(url:, target:)
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / script.sh
Created Apr 9, 2018
Cyrstal PKG_CONFIG_PATH macOS High Sierra
View script.sh
# Package libssl was not found in the pkg-config search path.
# Perhaps you should add the directory containing `libssl.pc'
# to the PKG_CONFIG_PATH environment variable
# No package 'libssl' found
# Package libcrypto was not found in the pkg-config search path.
# Perhaps you should add the directory containing `libcrypto.pc'
# to the PKG_CONFIG_PATH environment variable
# No package 'libcrypto' found
export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / script.sh
Last active Apr 7, 2018
Install Java10 Linux
View script.sh
mkdir ~/java10
cd ~/java10
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/10+46/76eac37278c24557a3c4199677f19b62/jdk-10_linux-x64_bin.tar.gz
tar -zxvf jdk-10_linux-x64_bin.tar.gz
cd jdk-10/
update-alternatives --install /usr/bin/java java ~/java10/jdk-10/bin/java 100
update-alternatives --config java
update-alternatives --install /usr/bin/javac javac ~/java10/jdk-10/bin/java 100
update-alternatives --config javac
update-alternatives --install /usr/bin/jar jar ~/java10/jdk-10/bin/jar 100
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / memory.rb
Last active Apr 25, 2018
Ruby Memory and Time Usage script
View memory.rb
def print_memory_usage
memory_before = `ps -o rss= -p #{Process.pid}`.to_i
yield
memory_after = `ps -o rss= -p #{Process.pid}`.to_i
puts "Memory: #{((memory_after - memory_before) / 1024.0).round(2)} MB"
end
def print_time_spent
time = Benchmark.realtime do
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / setup.sh
Last active Jan 23, 2017
Setup Mac for Development
View setup.sh
cd ~
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew analytics off
brew doctor
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
\curl -sSL https://get.rvm.io | bash -s stable
source /Users/edgarortega/.rvm/scripts/rvm
type rvm | head -1
rvm -v
brew install git node vim postgres tmux yarn ag
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / ssl.rb
Last active Aug 27, 2016
Ruby: Disable OpenSSL certificate verification
View ssl.rb
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
View test.rb
def gen(nums, digit)
result = []
nums.each_with_index do |num, i|
slice = nums[i, digit]
tmp = slice.concat(nums[i + digit])
result.push(tmp)
end
result
end
gen([0,1,2],1)
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / brew.sh
Last active Mar 8, 2016
Update and Clean Up Brew
View brew.sh
brew update && brew upgrade --all && brew cleanup && brew prune
You can’t perform that action at this time.