Skip to content

Instantly share code, notes, and snippets.

View danielgospodinow's full-sized avatar
🔊
I convert chalga to code

Daniel Gospodinow danielgospodinow

🔊
I convert chalga to code
View GitHub Profile
@danielgospodinow
danielgospodinow / ensureImagesFolder.js
Created July 13, 2019 13:21
Screentopia - ensure image folder function
function ensureImagesFolder(imageDirectory) {
if (!fs.existsSync(imageDirectory)) {
console.log("Creating folder for image storage ...");
fs.mkdirSync(imageDirectory);
}
}
@danielgospodinow
danielgospodinow / cleanupImages.js
Created July 13, 2019 13:24
Screentopia - cleanup images function
function cleanupImages(imageDirectory, imageDirectoryCapacity) {
const images = fs.readdirSync(imageDirectory);
if (images.length >= imageDirectoryCapacity) {
console.log("Cleaning up space ...");
fs.unlinkSync(imageDirectory + "/" + images.pop());
}
}
@danielgospodinow
danielgospodinow / updateBackground.js
Created July 13, 2019 13:56
Screentopia - update desktop background wallpaper
async function updateBackground(imageResolution, imageCategories, imageDirectory) {
console.log("Starting wallpaper change procedure ...");
try {
const imageResponse = await fetch(`https://source.unsplash.com/featured/${imageResolution}?${imageCategories}`);
const image = await download.image({ url: imageResponse.url, dest: imageDirectory });
await wallpaper.set(image.filename);
console.log("Wallpaper changed successfully!");
} catch (e) {
"use strict";
const fetch = require("node-fetch");
const download = require("image-downloader");
const wallpaper = require("wallpaper");
const schedule = require("node-schedule");
const fs = require("fs");
const imageDirectory = "./images";
const imageDirectoryCapacity = 10;
@danielgospodinow
danielgospodinow / repeatProcess.js
Created July 13, 2019 14:29
Screentopia - repeat process
schedule.scheduleJob("0 * * * *", async () => {
await ensureImagesFolder(imageDirectory);
await cleanupImages(imageDirectory, imageDirectoryCapacity);
await updateBackground(imageResolution, imageCategories, imageDirectory);
});
@danielgospodinow
danielgospodinow / pom.xml
Created August 5, 2019 08:28
Calcualtor Provider's Pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dg.osgi</groupId>
<artifactId>calculator-provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
@danielgospodinow
danielgospodinow / Calculator.java
Last active August 5, 2019 11:18
Calcualtor Provider's Interface
public interface Calculator {
int add(int a, int b);
int multiply(int a, int b);
}
@danielgospodinow
danielgospodinow / CalculatorImpl.java
Last active August 5, 2019 11:18
Calcualtor Provider's Implementation
import com.dg.osgi.calculator.provider.api.Calculator;
import org.osgi.service.component.annotations.Component;
@Component
public class CalculatorImpl implements Calculator {
public int add(int a, int b) {
return a + b;
}
@danielgospodinow
danielgospodinow / pom.xml
Created August 5, 2019 08:36
Calcualtor Consumer's Pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dg.osgi</groupId>
<artifactId>calculator-consumer</artifactId>
<version>1.0.0-SNAPSHOT</version>
@danielgospodinow
danielgospodinow / CalculatorConsumer.java
Last active August 5, 2019 11:17
Calcualtor Consumer
import com.dg.osgi.calculator.provider.api.Calculator;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component
public class CalculatorConsumer {
@Reference
private Calculator calculator;