Skip to content

Instantly share code, notes, and snippets.

View EdgarOrtegaRamirez's full-sized avatar
📝
​Learning!

Edgar Ortega EdgarOrtegaRamirez

📝
​Learning!
View GitHub Profile
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / file_downloader.rb
Last active July 6, 2018 22:45
Simple File Downloader in Ruby using Net::HTTP, it downloads by chuncks into a file to keep memory as low as possible
# frozen_string_literal: true
require "net/http"
class FileDownloader
attr_reader :uri, :http_response
HTTPS_SCHEME = "https"
def initialize(url:, target:)
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / memory.rb
Last active April 25, 2018 22:20
Ruby Memory and Time Usage script
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 / script.sh
Created April 9, 2018 04:45
Cyrstal PKG_CONFIG_PATH macOS High Sierra
# 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 April 7, 2018 21:48
Install Java10 Linux
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 / setup.sh
Last active January 23, 2017 03:49
Setup Mac for Development
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
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 March 8, 2016 14:16
Update and Clean Up Brew
brew update && brew upgrade --all && brew cleanup && brew prune
class Photo < ActiveRecord::Base
module Statues
QUEUED = 'queued'
NEW = 'new'
def self.values
constants.map(&method(:const_get))
end
# you can define more special methods as you wanted for Statues
end
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / gist:6141156
Created August 2, 2013 16:13
[Rails] fields_for inside fields_for
<%= fields_for @tour do |tour_fields| %>
<%= tour_fields.fields_for :dispatches, @dispatches do |dispatch_fields| %>
<tr>
<td><%= if dispatch_fields.object.published? then "Published"; elsif dispatch_fields.object.new_record? then "undefined"; else "Draft"; end%></td>
<td><%= dispatch_fields.object.dispatch_date %></td>
<td><%= dispatch_fields.object.venue %></td>
<td><%= dispatch_fields.object.address%></td>
<div class="dispatchFields">
<%= dispatch_fields.hidden_field :id, value: dispatch_fields.object.id unless dispatch_fields.object.id.nil? %>
<%= dispatch_fields.hidden_field :artist_id, value: current_artist.id %>
@EdgarOrtegaRamirez
EdgarOrtegaRamirez / gist:5835943
Created June 22, 2013 05:06
[Sublime Text] trim trailing spaces on save
"trim_trailing_white_space_on_save": true