Skip to content

Instantly share code, notes, and snippets.

@yoshprogrammer
yoshprogrammer / Index.html
Created September 10, 2016 21:27
Angular Help
<!DOCTYPE html>
<html>
<head>
<title>Social Hacks</title>
<!-- Angular 1 -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<!-- our custom JS code -->
<script src="dynamiclist.js"></script>
@yoshprogrammer
yoshprogrammer / hashtable.js
Created February 14, 2016 22:28
Hashtables JS
var getIndexBelowMaxForKey = function(str, max){
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = (hash<<5) + hash + str.charCodeAt(i);
hash = hash & hash; // Convert to 32bit integer
hash = Math.abs(hash);
}
return hash % max;
};
@yoshprogrammer
yoshprogrammer / CreateUser.js
Last active February 5, 2016 22:35
Weebly Could API - Create User
app.post('/api/user', function (req, res) {
//LIBS - The libs I used for this call.
//var _ = require('lodash'),
// Curl = require('node-libcurl').Curl,
// express = require('express'),
// app = express();
var body = _.pick(req.body, 'email'),
dataArray = JSON.stringify({
"email": body.email
@yoshprogrammer
yoshprogrammer / Create::User.js
Last active February 5, 2016 22:29
Weebly Cloud API - Create User
app.post('/api/user', function (req, res) {
//LIBS - The libs I used for this call.
//var _ = require('lodash'),
// Curl = require('node-libcurl').Curl,
// express = require('express'),
// app = express();
var body = _.pick(req.body, 'email'),
dataArray = JSON.stringify({
"email": body.email
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------*/
package com.unitnet.weebly;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import java.net.URI;
@yoshprogrammer
yoshprogrammer / triangle.rb
Last active August 29, 2015 14:01
print_triangle
# The print_line method is here to help you.
# Conceptually, it prints out a row of "count" *'s. Run it yourself to
# see how it works. Experiment with different inputs.
def print_line(count)
for i in 1..count
print "*" # This prints a single "*"
end
@yoshprogrammer
yoshprogrammer / print_square.rb
Created May 27, 2014 02:12
print_square_attempt
def print_line(count)
for i in 1..count
print "*" # This prints a single "*"
end
print "\n" # This forces the output to the next like, like hitting "return" on the keyboard
end
# We can call methods we've defined ourselves. In this case, we want
@yoshprogrammer
yoshprogrammer / Exercise_36.rb
Last active August 29, 2015 14:01
Exercise_36
def max(list)
max_so_far = list.first
for item in list
if item > max_so_far
max_so_far = item
end
end
return max_so_far
end
@yoshprogrammer
yoshprogrammer / Josh_Brown_35.rb
Last active August 29, 2015 14:01
35-Count-In-List-Attempt-JoshuaBrown
# Method name: count_in_list(list, item_to_count)
# Inputs: 1. a list of anything, 2. an item for us to count in the list
# Returns: The number of times our item is contained in the input list
# Prints: Nothing
#
# For example,
# count_in_list([1,2,3], 1) == 1
# count_in_list([1,2,3], -1) == 0
# count_in_list([1,1,1], 1) == 3

Questions

How do I get it to return per line, isn't that the point of this exercise? For instance, how would I get it to return each value, such as line 35's list "total = 0" on one line, next "total = 0 + 11", next line "total = 11+22".

I could not find a way to do it like, 'running_total = return item[0], return item[0] + item[1]...item[i]'.

First, it's good that you understand what you need to do and are referring to the last item of the list as item[i]. Keep in mind that if the list is in the variable list then to get the item at, say, index 10, we want list[10], not item[10]. Imagine if you could write code like this:

def sum(list)