Skip to content

Instantly share code, notes, and snippets.

@aspencer8111
aspencer8111 / sms_script.rb
Last active December 15, 2015 18:09
A quick ruby script to send text msgs to my friends - uses twilio
require 'rubygems'
require 'twilio-ruby'
account_sid = "<<>>"
auth_token = "<<>>"
client = Twilio::REST::Client.new account_sid, auth_token
from = "+<<>>" # Your Twilio number
# "Kile" => "+<<>>",
# "Cassie" => "+<<>>"
class Rot13
attr_accessor :text
def initialize(text)
@text = text
end
def encrypt
@text = @text.tr('a-zA-Z', 'n-za-mN-ZA-M')
end
@aspencer8111
aspencer8111 / relection.js
Created June 21, 2016 16:01
See available properties (with or without chain) on a Javascript Object
// See a list of properties for a givin oject (includeing all in prototype chain)
for(var prop in obj){
console.log(prop ": " + obj[prop])
}
// See only properties in the object (no protochain)
for(var prop in obj){
if (obj.hasOwnProperty(prop)){
console.log(prop ": " + obj[prop])
// What will this code print?
function can_ride(height) {
if(height > 6) {
console.log("You can ride the ride");
}else if(height !== 5) {
console.log("You can't ride");
}else{
console.log("stop");
}
@aspencer8111
aspencer8111 / js_functions.md
Last active October 27, 2018 19:43
Javascript functions explained

Learn your JS functions and arguments

A function has a few parts:

  1. The declaration: function ...
  2. The name: function foo...
  3. The arguments: function foo(arguments go here!)...
  4. The code to be executed: (inside the { } brackets):
function foo() { 
@aspencer8111
aspencer8111 / bubble_sort.rb
Created March 13, 2017 14:46
A simple bubble sort algorithm in ruby
def bubble_sort(array)
loop do
swapped = false
(array.length-1).times do |i|
if array[i] > array[i + 1]
array[i], array[i + 1] = array[i + 1], array[i]
swapped = true
end
end
@aspencer8111
aspencer8111 / quicksort.rb
Created March 13, 2017 15:01
QuickSort added to array class
class Array
def quicksort
return [] if empty?
pivot = delete_at(rand(size))
left, right = partition(&pivot.method(:>))
return *left.quicksort, pivot, *right.quicksort
end
end
@aspencer8111
aspencer8111 / fib.rb
Created March 13, 2017 15:13
Fibonacci Sequence in Ruby
def fib(n)
return n if (0..1).include?(n)
fib(n - 1) + fib(n - 2)
end
@aspencer8111
aspencer8111 / bank_account.rb
Last active May 8, 2017 14:49
Simple solution to Bloc's bank account exercise
class BankAccount
attr_reader :balance
def initialize(balance)
@balance = balance
end
def display_balance
@balance
end
Pull-request Checklist
======================
A checklist I shamelessly stole from @anhari.
Sweep
-----
[ ] Any unnecessary comments?
[ ] Deleted all debugging statements?