Skip to content

Instantly share code, notes, and snippets.

View danman01's full-sized avatar

Danny Kirschner danman01

View GitHub Profile
@danman01
danman01 / rails_association_testing.rb
Last active May 12, 2017 15:28
verifying rails associations exist
# belongs_to side contains the foreign key
class Comment < ActiveRecord::Base
belongs_to :example
end
# has_one side does not contain the foreign key
class Example < ApplicationRecord
belongs_to :user
has_one :comment
validates :text, :user, presence: true
@danman01
danman01 / reference_type_change_in_function.js
Created July 24, 2017 16:56
changing props of reference type within function
> const menu = {
... 'burger': 5.99,
... 'salad': 4.99,
... 'drink': 1.00
... }
undefined
> menu
{ burger: 5.99, salad: 4.99, drink: 1 }
> const addProperty = function addProperty(obj, prop, val) {
... obj[prop] = val
@danman01
danman01 / generate_secrets.sh
Created July 26, 2017 02:53
generate secrets for rails projects
function generate_secrets {
echo SECRET_KEY_BASE_DEVELOPMENT=`bundle exec rake secret` | tee .env && echo SECRET_KEY_BASE_TEST=`bundle exec rake secret` | tee -a .env
}
1.upto(10) do |i|
puts "i"
return 'hey I\'m returning!'
end
# what is returned? Why?
def count(upto)
msg = 'hey I\'m returning!'
1.upto(upto) do |i|
puts 'i'
@danman01
danman01 / deploy.log
Created August 13, 2017 02:09
heroku ember-cli-rails deploy log
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NPM_CONFIG_PRODUCTION=true
remote: NODE_VERBOSE=false
@danman01
danman01 / atom_teach_resize.sh
Created August 29, 2017 23:57
atom_teach_resize
#!/bin/bash
# source into your .bash_profile
# call with atom_teach_resize and turn off with atom_teach_resize off
function atom_teach_resize() {
if [[ ! "$1" = "off" ]] && [[ ! -z "$1" ]]; then
echo "arg1: only \"off\" acceptable!"
exit
elif [[ ! -z "$1" ]]; then
COMMENT="//"
@danman01
danman01 / update_post_fullstack_project.rb
Last active September 10, 2017 22:07
update_post_fullstack_project.sh
##########
######
###### As a new user with ID 2:
[email protected]: blog_rails-api-template (dk)* $ [email protected] PASSWORD=q123 sh scripts/sign-up.sh
HTTP/1.1 201 Created
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: application/json; charset=utf-8
@danman01
danman01 / json.md
Created December 14, 2017 18:53
what is JSON?

What is JSON?

JavaScript Object Notation or JSON is a text-notation format for the serialization of structured data. The JSON format describes how to represent and structure the data so that it can easily written, transferred and parsed by the receiver. JSON is easy for humans to read and write. It’s also easy for machines to programmatically parse and generate. By looking at a document structured using the JSON format, one can visually read the data and the structure of the data, such as how data is related to other data parent or child item. This ease of use has made JSON one of the most popular ways to format and interchange data.

The reason one might use the JSON format to structure their data is to provide for ease of serialization. That means the data can easily be translated from an object into a format that can be stored (for example, in a file) or transmitted (for example, across a network). JSON can represent four primitive data types: String, Number, Boolean and Null, as well as two structured t

@danman01
danman01 / binary_search.rb
Created December 21, 2017 19:20
binary_search_ruby
#!/usr/bin/env ruby
# Usage: ruby binary_search.rb [debug] 50 0 100
# Returns: [optional: count of tries] @item, when found within first and last (not inlusive)
module Algorithms
class BinarySearch
def initialize
@n = 0
@danman01
danman01 / ripped_books_v1.js
Last active February 8, 2018 21:55
ripped books: find min/max pages that an array of ripped pages could represent.
Sure, there's a way to use reduce and do this all in one line. This v2 is 477 bytes as is.
test data:
const sample_input = [[7,8,100,101,222,223],
[ 2,3,88,89,90,103,177 ],
[ 2,3,6,7,10,11 ],
[ 1 ],
[ 1,2 ]]
const sample_output = [ "4/5","5/6","3/6","1/1","1/2" ]