Skip to content

Instantly share code, notes, and snippets.

@aspencer8111
aspencer8111 / gist:f5fb769ae16a16cd5346b2ac53a79c07
Created March 28, 2023 14:28
Sort word by repeating letters
# @param {String} s
# @return {String}
def frequency_sort(s)
letter_count = {}
s.split('').each do |letter|
if !letter_count[letter].nil?
letter_count[letter] = letter_count[letter] + 1
else
letter_count[letter] = 1
@aspencer8111
aspencer8111 / BottleSong.rb
Created March 18, 2023 16:04
99 Bottles of OOP - Pre-read attempt
#!/usr/bin/ruby
class BottlesSong
def initialize(number_of_bottles)
@number_of_bottles = number_of_bottles
end
def sing
bottles.each do |number_of_bottles|
if number_of_bottles == 1
@aspencer8111
aspencer8111 / pizza.txt
Created February 21, 2019 20:58
Please tell me how you feel about putting pineapple on pizza
Please send a 2 - 3 sentance email telling me how you feel about putting pineapple on pizza to (pg-13 language pls):
[email protected]
Sorry it is a long email address :( . This is just for a demo though :).
@aspencer8111
aspencer8111 / getting_to_know.txt
Last active February 5, 2019 22:37
3. Getting to know you and Rails!
1. Explain join tables to me. (i.e. a student has_one teacher through classrooms). What are the advantages/disatvantages
2. Assuming a I have the following code in a standard rails routes file, please
give me the http/RESTful verb (GET, PUT, POST, or DELETE) AND each url path (i.e. /posts) AND controller#action
resources :posts
// first one as an example
GET /posts posts#index
3. What part of rails 6 are you looking forward to the most/least?
@aspencer8111
aspencer8111 / views->posts->index.html.erb
Last active February 6, 2019 16:41
2. This is a new PR, please review and give feedback
<!-- assume that there is a posts controller with an index method that looks like this:
def index
@posts = Post.all
end
-->
<ul>
<% @posts.each do |post| %>
@aspencer8111
aspencer8111 / modeling.rb
Created February 4, 2019 17:12
1. Modeling Discussion
```
Pretend we are building a Rails application to help a new library in tracking their book inventory.
This includes the checking out, checking in, adding, and removing of books.
Also any other models you believe we will need.
```
@aspencer8111
aspencer8111 / Textbox.js
Last active August 27, 2018 21:49
for lexy snowman game
import React, { Component } from 'react';
import words from '../Data/words.json'
class WordBox extends Component {
constructor() {
super()
const randomNumber = Math.floor( Math.random() * words.length )
this.state = {
randomWord: words[randomNumber]
@aspencer8111
aspencer8111 / ms.js
Last active August 21, 2018 01:30
For minesweeper
import React, { Component } from 'react';
const BASE_URL = 'https://minesweeper-api.herokuapp.com/'
class Minesweeper extends Component {
constructor(props) {
super(props);
this.state = {
game: {
board: [],
@aspencer8111
aspencer8111 / el.md
Last active March 5, 2018 15:13
Adding an event listener

Which of the following is a valid way to register an event and listener in plain JavaScript?

Assume you have already found someElement in the DOM (i.e. let someElement = document.querySelector('#someElement'))

a) someElement.addEventListener('click', function() { console.log('clicked!') });

b) someElement.addEventListener('onClick', function() { console.log('clicked!') });

c) someElement.addEventListener(function() { console.log('clicked!') });

```javascript
let url = 'https://newsapi.org/v2/top-headlines?sources=hacker-news&apiKey=<YOUR API KEY GOES HERE>'

fetch(url)
  .then((r) => { return r.json() })
  .then(
    (data) => {
      let results = data.articles // get the array of results from the data object