Skip to content

Instantly share code, notes, and snippets.

def square_root (n,d)
g1 = (n* 1.0) / 2
g2 = (g1 + (n /g1)) /2
while (g1 - g2).abs >= d
g1 = g2
g2 = (g1 + (n / g1)) / 2
end
g2
end
# Determine if a number is a prime number
def square_root(n,d)
g1 = (n * 1.0) / 2
g2 = (g1 + (n / g1)) / 2
while (g1 - g2).abs >= d
g1 = g2
g2 = (g1 + (n / g1)) / 2
end
g2
end
# Class activity 1
def list_range(list_):
if len(list_) == 1:
return [list_[0]]
smallest = list_[0]
largest = list_[0]
for item in list_:
if item > largest:
largest = item
elif item < smallest:
def earliest_letter word
#word = word.downcase
earliest = word[0]
word.split('').each do |letter|
if letter < earliest
earliest = letter
end
end
earliest
end
@johnotu
johnotu / addressbook.html
Created January 2, 2017 11:18
A Simple Addressbook using a DevLess Backend
<!DOCTYPE html>
<html>
<head>
<title>Address Book</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
button{margin: 0 20px;}
</style>
</head>
<body>
@johnotu
johnotu / API.md
Created July 14, 2017 06:45 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@johnotu
johnotu / index.css
Created August 19, 2017 02:46
Simple template for HNG Internship Stage-2 personal page task
.container {
text-align: center;
padding: 1.5em 0;
}
img {
width: 40%;
height: auto;
}
const quickReplyTags = (tags, sliceSet, beginSlice, endSlice) => {
// slice the elements of the array to the desired set size
let slicedTags = tags.slice(beginSlice, endSlice);
// form an array of quick replies with title and payload
let quickReplies = slicedTags.map(tag => {
return {
"content_type": "text",
"title": tag.title,
[
{
_id: '59ed1ed9be3ee700123e4e4a',
title: 'shoes',
status: 'Active',
__v: 0,
},
{
_id: '59ed1ee7be3ee700123e4e4b',
title: 'casual',
@johnotu
johnotu / product-quickreplies.js
Last active December 11, 2017 01:40
Repeatedly generate different sets of quick replies from a products array
const productQuickreplies = (products, sliceSet, beginSlice, endSlice) => {
// slice the elements of the array to the desired set size
let slicedProducts = products.slice(beginSlice, endSlice);
// form an array of quick replies with title and payload
let quickReplies = slicedProducts.map(product => {
return {
"content_type": "text",
"title": product.title,