Skip to content

Instantly share code, notes, and snippets.

View marka2g's full-sized avatar
🎯
Focusing

Mark Sadegi marka2g

🎯
Focusing
View GitHub Profile
@marka2g
marka2g / README.md
Created May 20, 2019 23:06 — forked from clhenrick/README.md
PostgreSQL & PostGIS cheatsheet (a work in progress)
@marka2g
marka2g / migrate_postgresql_database.md
Created May 20, 2019 22:38 — forked from olivierlacan/migrate_postgresql_database.md
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@marka2g
marka2g / hash_array_to_csv.rb
Created May 10, 2019 01:12 — forked from christiangenco/hash_array_to_csv.rb
Ruby hash array to CSV
class Array
def to_csv(csv_filename="hash.csv")
require 'csv'
CSV.open(csv_filename, "wb") do |csv|
csv << first.keys # adds the attributes name on the first line
self.each do |hash|
csv << hash.values
end
end
end
@marka2g
marka2g / gist:32a77caa591180eca070bf676298cb51
Created February 26, 2019 18:24 — forked from wrburgess/gist:2187164
Setting up a Rails has_many :through relationship with meaningful relationship table #rails #activerecord #relations

##References

##Create Models

Create tables:

rails g model Location
rails g model User
rails g model Checkin
@marka2g
marka2g / skip_callbacks.rb
Last active January 10, 2019 01:32
Example of using skip_callbacks
# require 'active_record'
# ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db.sqlite3')
# ActiveRecord::Schema.define do
# create_table :users, force: true do |t|
# end
# end
class ActiveRecord::Base
cattr_accessor :skip_callbacks
end
class User < ActiveRecord::Base
@marka2g
marka2g / node-npm-install.md
Created December 19, 2018 19:58 — forked from rcugut/node-npm-install.md
Install node & npm on Mac OS X with Homebrew

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

Solution

This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

@marka2g
marka2g / gist:58b3928e30c3a882ec69e5daa28fd71b
Created September 11, 2018 23:38 — forked from chrissimpkins/gist:5bf5686bae86b8129bee
Atom Editor Cheat Sheet (Sweetmeat)

Use these rapid keyboard shortcuts to control the GitHub Atom text editor on Mac OSX.

Key to the Keys

  • ⌘ : Command key
  • ⌃ : Control key
  • ⌫ : Delete key
  • ← : Left arrow key
  • → : Right arrow key
  • ↑ : Up arrow key

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@marka2g
marka2g / output_hours.md
Last active September 6, 2018 18:33
Output Hour Tracking

Output Hour Tracking

Hours(Current)

Date Hours Spent Daily Total Running Totals
09-05-18 signed full-time cont 16
09-04-18 10am - 6pm (-1 hours for lunch) 16
08-31-18 11am - 3pm 3 (-1 hours for lunch) 10
08-30-18 10am - 6pm 7 (-1 hours for lunch) 7