Skip to content

Instantly share code, notes, and snippets.

BetterProgramming

Block or report user

Report or block BetterProgramming

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View selectionSort.js
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
}
View swapIndex.js
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
}
}
View coffee.java
// see repo for full code
boolean milk;
boolean soy;
boolean mocha;
boolean whip;
// and their getters and setters
public int cost() {
View Beverage.java
public abstract class Beverage {
String desc = "unknown beverage";
public String getDescription() {
return desc;
}
public abstract int cost();
}
View darkroast.java
public class DarkRoast extends Beverage {
public DarkRoast() {
desc = "Dark roast";
}
@Override
public int cost() {
return 20;
}
}
View CondimentDecorator.java
public abstract class CondimentDecorator extends Beverage {
Beverage beverage;
public abstract String getDescription();
}
View mocha.java
public class Mocha extends CondimentDecorator {
public Mocha(Beverage b) {
beverage = b;
}
@Override
public String getDescription() {
return beverage.getDescription() + ", Mocha";
}
@Override
public int cost() {
View mocha.java
public class Mocha extends CondimentDecorator {
public Mocha(Beverage b) {
beverage = b;
}
@Override
public String getDescription() {
return beverage.getDescription() + ", Mocha";
}
@Override
public int cost() {
View spider.py
# -*- 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):
View electronicsspider.py
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/'
You can’t perform that action at this time.