Skip to content

Instantly share code, notes, and snippets.

View KonnorRogers's full-sized avatar

Konnor Rogers KonnorRogers

View GitHub Profile
@KonnorRogers
KonnorRogers / Gemfile_lock_or_gemspec.txt
Last active January 21, 2019 02:32
Gemfile.lock vs *.gemspec
Include a Gemfile.lock in your repo when not creating a gem
Use a *.gemspec when creating a rubygem and
DO NOT include a Gemfile.lock
Place all dependencies in the *.gemspec
@KonnorRogers
KonnorRogers / http_net_request.rb
Last active January 14, 2019 17:47
GitHub API v4 requests
# For forming a github v4 API request via Net::HTTP
# load the library, it will auto require the uri library
require 'net/http'
# githubs api url
endpoint_url = 'https://api.github.com/graphql'
# json formatted graphql request
# taken from docs - api v4
@KonnorRogers
KonnorRogers / setup.bash
Last active January 15, 2019 05:26
Setting up a new droplet
username='foo'
adduser $username
adduser $username sudo
su - $username
@KonnorRogers
KonnorRogers / convert.txt
Last active January 21, 2019 02:33
Converting FAT32 to NTFS flash drive
From windows:
open up command prompt by hitting start and searching for cmd
type:
convert F:/fs:ntf
Where F: is the directory of the removable flash drive / media
fs:ntfs simply goes from FAT to NTFS
@KonnorRogers
KonnorRogers / link.txt
Created January 28, 2019 03:02
Setting up cygwin / cmder / zsh
@KonnorRogers
KonnorRogers / alternative_net_http_request.rb
Last active April 12, 2019 05:52
Adding an ssh key to github via Ruby with Net::HTTP or Rest-Client
require 'net/http'
require 'json'
uri = URI('https://api.github.com/user/keys')
token = "token #{ENV['MY_SUPER_SECRET_API_TOKEN']}"
ssh_key_content = File.read(File.join(Dir.home, '.ssh', 'id_rsa.pub'))
ssh_key_title = 'my_title'
ssh_content = { 'title' => ssh_key_title,
@KonnorRogers
KonnorRogers / correct_extend.rb
Created April 5, 2019 19:27
Extending a module
module ExtendMe
def extension_method
puts "Hello from ExtendMe!"
end
end
class Klass
extend ExtendMe
def self.extended
@KonnorRogers
KonnorRogers / simple_ssh_keygen_wrapper.rb
Created April 6, 2019 00:02
SSH key generation in ruby
# This isnt meant to provide all options, just my simple wrapper for personal purposes
def generate_ssh_key
type = 'rsa'
bits = 4096
comment = '[email protected]'
system("ssh-keygen -t #{type} -b #{bits} -C #{comment}")
end
@KonnorRogers
KonnorRogers / find_ssh_key.rb
Last active April 13, 2019 20:48
Retrieving all github ssh keys and iterating through them to match your key
# This is using the v3 of github API, I could not find a guide for ssh keys
# within the github api v4
# reading public keys, you need admin:public_key & admin:read_key
# https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
# Both libraries are part of the ruby standard library
require 'net/http'
require 'json'
@KonnorRogers
KonnorRogers / form_for.html.erb
Created April 18, 2019 19:16
form_for vs form_tag vs form_with params
<%= form_for(:session, url: login_path) do |f| %>
<%= f.label :name %><br>
<%= f.text_field :name %><br>
<%= f.submit "Login" %>
<% end %>
<%# To access the params in your controller its simply: %>
<%# params[:session][:name] %>