Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Day samuraijane

View GitHub Profile
View xxr.sh
#let Terminal know that you are using bash shell (the line that begins with '#!' is known as the interpreter line)
#!/bin/sh
#set the version number for this
#version 0.0.3 (8 July 2016)
#create a variable to hold the name of the new repository
#the '$1' denotes the first argument passed to this shell
#for example, entering 'xxr repo-name' in Terminal stores the first argument, or 'repo-name', in the variable 'repo'
repo=$1
View .alias
alias gs='git status -sb'
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gd='git diff'
alias gl='git log'
alias gp='git push origin master'
alias gpush='git push origin'
alias gdrop='git stash drop stash@{0}'
alias rebase='git pull --rebase'
View .bash_profile
# --------------------------------------------------------------
# IMPORT ALIAS COMMANDS
# --------------------------------------------------------------
. ~/.alias
# --------------------------------------------------------------
# NODE VERSION MANAGER
# --------------------------------------------------------------
export NVM_DIR="$HOME/.nvm"
@samuraijane
samuraijane / key-value-array.php
Created Apr 23, 2015
Key/value pairs in PHP are common so when you need to iterate through an array and return only the value, this is how you do it.
View key-value-array.php
<?php
$array = array(
"Events",
"Webinars",
"Cloud",
"Collaboration",
"Innovation",
"Tips"
)
@samuraijane
samuraijane / hash_from_two_arrays.rb
Created Apr 17, 2015
Sometimes you need to create a new hash that blends two arrays, where the content in first array become the keys and the content in the second array become the values in the new hash. You can also assign that same value to each key if necessary.
View hash_from_two_arrays.rb
# OPTION 1
# array_a is an array that holds what will become the keys in the new hash.
# array_b is an array that holds what will become the values in the new hash.
# Create a new empty hash.
my_hash = {}
# Send array_a and array_b into the new hash.
array_a.each_with_index { |key, value| my_hash[key] = array_b[value] }
# This works well for arrays that have the same amount of content so that things
# line up. I haven't researched what happens with one array has more content
# than the other.
@samuraijane
samuraijane / hash_key_options.rb
Created Apr 17, 2015
To pull just the keys out of a hash, you have a few options but they are not interchangeable.
View hash_key_options.rb
# This works in IRB but I could not get it to output in a browser. The command
# 'puts' will not output to a browser but with other methods, doing something
# like '{ |x| x}' usually works but not here.
hash.each_key { |x| puts x }
#This works to output to a browser. The output is an array.
hash.key
@samuraijane
samuraijane / nested_map_variable.rb
Created Mar 31, 2015
When dealing with nested maps that create an array you need to access, where you define the variable that holds the array is important. See the differences here.
View nested_map_variable.rb
#Example 1
$myvariable= imgarray.map do |layouts|
layouts[ 'layouts' ].map do |layout_name|
layout_name[ 'layout_name' ]
end
end
#Placing the variable at the beginning of the loop returns an array within an array:
#[["annie", "billy", "charlie", "danny", "eddy", "fergie", "granny", "henry", "jenny", "kelsey"]]
#Example 2
@samuraijane
samuraijane / block_or_line.rb
Last active Aug 29, 2015
You can write using a block or write the code on one line when nesting maps. This code shows you how to do both.
View block_or_line.rb
#Code with block
$myvariable= imgarray.map do |layouts|
layouts[ 'layouts' ].map do |layout_name|
layout_name['layout_name']
end
end
#Code on one line
$myvariable= (imgarray.map{ |layouts| (layouts[ 'layouts' ]).map{ |layout_name| (layout_name[ 'layout_name' ]) }} )
@samuraijane
samuraijane / to_s versus join.rb
Last active Aug 29, 2015
to_s and join are both used to convert to string but they are not exactly the same (research pending).
View to_s versus join.rb
<%= 'filexyz ' + (filexyz.class).to_s %> #>filexyz String
<%= (['filexyz'] + [filexyz.class]).join(" ") %> #>filexyz String
@samuraijane
samuraijane / Nested Maps.rb
Created Mar 25, 2015
The proper way to nest maps
View Nested Maps.rb
<%= hobbiestostring = '[' + (friends.map{ |friend| (friend[ 'children' ]).map{ |nino| nino[ 'name'] }}).join(", ") + ']' %>