Skip to content

Instantly share code, notes, and snippets.

View BetterProgramming's full-sized avatar

BetterProgramming

View GitHub Profile
const selectionSort = (nums) => {
checkLoopInvariant(nums, input, 0) //check during initialization
for (let i = 0; i < nums.length - 1; i++) {
checkLoopInvariant(nums, input, i) //check at each iteration
}
checkLoopInvariant(nums, input, nums.length) //check at the
return nums
}
let smallest = nums[i]
let swapIndex = i
// Search the remainder of the array for the smallest number
for (let j = i + 1; j < nums.length; j++) {
if (nums[j] < smallest) {
smallest = nums[j];
swapIndex = j
}
}
// see repo for full code
boolean milk;
boolean soy;
boolean mocha;
boolean whip;
// and their getters and setters
public int cost() {
public abstract class Beverage {
String desc = "unknown beverage";
public String getDescription() {
return desc;
}
public abstract int cost();
}
public class DarkRoast extends Beverage {
public DarkRoast() {
desc = "Dark roast";
}
@Override
public int cost() {
return 20;
}
}
public abstract class CondimentDecorator extends Beverage {
Beverage beverage;
public abstract String getDescription();
}
public class Mocha extends CondimentDecorator {
public Mocha(Beverage b) {
beverage = b;
}
@Override
public String getDescription() {
return beverage.getDescription() + ", Mocha";
}
@Override
public int cost() {
public class Mocha extends CondimentDecorator {
public Mocha(Beverage b) {
beverage = b;
}
@Override
public String getDescription() {
return beverage.getDescription() + ", Mocha";
}
@Override
public int cost() {
# -*- coding: utf-8 -*-
import scrapy
class ElectronicsSpider(scrapy.Spider):
name = "electronics"
allowed_domains = ["www.olx.com.pk"]
start_urls = ['http://www.olx.com.pk/']
def parse(self, response):
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
class ElectronicsSpider(CrawlSpider):
name = "electronics"
allowed_domains = ["www.olx.com.pk"]
start_urls = [
'https://www.olx.com.pk/computers-accessories/',
'https://www.olx.com.pk/tv-video-audio/',
'https://www.olx.com.pk/games-entertainment/'