Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 001-github-repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
count=0
repos=()

while ((count < 500)); do
response=$(curl -s "https://api.github.com/orgs/apache/repos?page=$page&per_page=100")
if [ "$response" == "[]" ]; then
break
fi
repos+=("$response")
((page++))
count=$(($count + $(echo "$response" | jq '. | length')))
done

sorted_repos=$(echo "${repos[@]}" | jq -s 'add | .[] | select(.stargazers_count != null) | {stars: .stargazers_count, name: .name, url: .html_url}' | jq -s 'sort_by(.stars) | reverse')

for row in $(echo "${sorted_repos}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}

echo Stars: $(_jq '.stars'), Name: $(_jq '.name'), URL: $(_jq '.url')
done
32 changes: 32 additions & 0 deletions 002-github-repos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const https = require('https');

function fetchRepos() {
const options = {
hostname: 'api.github.com',
path: '/orgs/apache/repos',
method: 'GET',
headers: {
'User-Agent': 'Node.js'
}
};

const req = https.request(options, res => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
const repos = JSON.parse(data);
const sortedRepos = repos
.map(repo => ({ stars: repo.stargazers_count, name: repo.name }))
.sort((a, b) => b.stars - a.stars);

for (const repo of sortedRepos) {
console.log(`${repo.stars} ${repo.name}`);
}
});
});

req.on('error', error => console.error(error));
req.end();
}

fetchRepos();
24 changes: 24 additions & 0 deletions 003-download-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const axios = require('axios');
const fs = require('fs').promises;
const sharp = require('sharp');

async function downloadAndProcessImage() {
const url = 'https://source.unsplash.com/random';
const response = await axios.get(url, { responseType: 'arraybuffer' });
const originalImage = Buffer.from(response.data, 'binary');

await fs.writeFile('original.png', originalImage);

const image = sharp(originalImage);
const metadata = await image.metadata();

const resizedImage = await image
.resize({ width: Math.round(metadata.width * 0.5) })
.toBuffer();

await sharp(resizedImage)
.greyscale()
.toFile('greyscale.png');
}

downloadAndProcessImage().catch(console.error);
20 changes: 20 additions & 0 deletions 003-download-image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import requests
from PIL import Image

url = "https://source.unsplash.com/random"
response = requests.get(url)

with open("original.png", "wb") as file:
file.write(response.content)

# Load the image
image = Image.open("original.png")

# Resize the image 50% smaller
resized_image = image.resize((int(image.width * 0.5), int(image.height * 0.5)))

# Convert the image to greyscale
greyscale_image = resized_image.convert("L")

# Save the greyscale image
greyscale_image.save("greyscale.png")
Loading