Skip to content

Instantly share code, notes, and snippets.

😎

Adan Alvarado aalvarado

😎
Block or report user

Report or block aalvarado

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aalvarado
aalvarado / solution.rb
Created Mar 10, 2015
PermMissingElem
View solution.rb
def solution(a)
((( a.size + 2 ) * ( a.size + 1 )) / 2) - ( a.reduce(&:+) || 0 )
end
View missing_int_solution.rb
# Missing int from unsorted array and with arbitrary starting int
def solution(a=[])
sum = 0
min = a.first
max = a.last
a.each do |e|
sum += e
min = e if e < min
View sti_scope.rb
# http://stackoverflow.com/questions/28711074/undefined-method-error-for-scope-on-sti-subclass
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails'
gem 'arel'
gem 'sqlite3'
GEMFILE
View inverse_of_test.rb
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.2.0'
gem 'arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
View gist:46e5678f3c65492010e5
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
View 99-displaymagic.rules
#/etc/udev/rules.d/99-displaymagic.rules
# enable LVDS on HDMI disconnect
SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/displaymagic.sh"
@aalvarado
aalvarado / .psqlrc
Last active Aug 29, 2015
postgresql DEVELOPMENT configuration
View .psqlrc
\pset null 'NULL'
\set HISTFILE ~/.psql_history- :HOST - :DBNAME
\set HISTSIZE 100000
\timing
\set PROMPT1 '(%n@%M:%>) [%/] > '
\set PROMPT2 ''
\encoding unicode
\timing
\pset pager always
\setenv LESS '-iMSsx2 -FX'
@aalvarado
aalvarado / calls.rb
Last active Mar 4, 2019
Faraday calls with cookies against Sinatra / Rack
View calls.rb
require 'faraday-cookie_jar'
#all one liners because it's easier for irb/pry
conn = Faraday.new(:url => 'http://localhost:3535'){ |f| f.request :url_encoded; f.response :logger; f.adapter Faraday.default_adapter; f.use :cookie_jar }
res = conn.get('/route')
cookie2 = res.headers['set-cookie']
@aalvarado
aalvarado / my.cnf
Last active Dec 20, 2015
Faster mysql restores
View my.cnf
# /opt/local/etc/mysql5/my.cnf
innodb_buffer_pool_size=192M
innodb_additional_mem_pool_size=96M
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=64M
innodb_file_per_table
key_buffer = 32M
max_allowed_packet = 32M
View crap.cpp
#include <iostream>
class Crap {
private:
int times;
public:
Crap() {
times = 0;
}
You can’t perform that action at this time.