Skip to content

Instantly share code, notes, and snippets.

View peterkracik's full-sized avatar
👨‍🚀

Peter Kracik peterkracik

👨‍🚀
View GitHub Profile
@peterkracik
peterkracik / gitlab-ci.yml
Last active June 26, 2020 08:00
Scheduled Backup Gitlab CI/CD
variables:
HOST_PRODUCTION: "root@ip-address-of-host"
PROJECT_NAME: my_project
DB_EXPORT_PATH: /var/backups/mysql
DB_CONTAINER: project-db
backup db:
image: alpine
stage: build
only:
@peterkracik
peterkracik / firebase-download-file.ts
Created June 26, 2020 05:16
Getting a file from bucket as a stream
import * as admin from 'firebase-admin';
admin.initializeApp({
credential: admin.credential.applicationDefault()
});
exports.downloadFile = httpRequest.onRequest((req, res) => {
const bucket = admin.storage().bucket('my_bucket'); // initialize storage as admin
const stream = bucket.file('path/to/file.jpg').createReadStream(); // create stream of the file in bucket
// pipe stream on 'end' event to the response
return stream
@peterkracik
peterkracik / firebase-signed-url.ts
Created June 26, 2020 05:08
FIrebase - get signed url
import * as functions from 'firebase-functions';
import { Storage, GetSignedUrlConfig } from '@google-cloud/storage';
exports.getUrl = functions.https.onCall(async (data, context) => {
const storage = new Storage();
// options of temporary access to file
const options: GetSignedUrlConfig = {
version: 'v2', // default value
action: 'read', // read | write | delete | resumable
expires: Date.now() + 1000 * 60 * 60, // expire date, one minute from now
@peterkracik
peterkracik / firebase-download-url.ts
Created June 26, 2020 04:59
Retrieving download url from Firebase Storage
import { AngularFireStorage } from '@angular/fire/storage';
class MyClass {
constructor(private storage: AngularFireStorage) {}
public async getUrl(filepath: string) {
this.storage.ref(filePath)
.getDownloadURL() // it returns url value as observable
.subscribe((url: string) => {
// actions with url value
@peterkracik
peterkracik / firebase-download-public-link.ts
Last active June 26, 2020 04:52
Get and store firebase storage public url
@peterkracik
peterkracik / 1.scss
Last active June 5, 2020 17:14
scss 1
.language-select {
position: relative;
text-transform: uppercase;
@include large {
padding: 1em 2em 1em 4em;
margin-left: 2em;
border-left: 1px solid rgba($color-black, 0.1);
}
@include small-medium {
padding: 4rem 0 0;
@peterkracik
peterkracik / firebase-timestamp-to-js-date.js
Created May 17, 2020 14:15
Script to convert firebase timestamp to JS format date
public static convertDate(firebaseObject: any) {
if (!firebaseObject) return null;
for (const [key, value] of Object.entries(firebaseObject)) {
// covert items inside array
if (value && Array.isArray(value) )
firebaseObject[key] = value.map(item => self.convertDate(item));
// convert inner objects
@peterkracik
peterkracik / node-js-mailgun-send.js
Last active May 13, 2020 16:26
node.js send mail with mailgun
const nodemailer = require('nodemailer');
const mg = require('nodemailer-mailgun-transport');
// Mailgun authentication
const auth = {
auth: {
api_key: process.env.API_KEY, // Mailgun API key
domain: process.env.DOMAIN // Mailgun domain ie. mg.mydomain.com
},
host: 'api.eu.mailgun.net' // for non-eu only api.moailgun.net

Intro

Milan si plánuje výlet a potrebuje si do batohu vhodne usporiadať oblečenie podľa toho, ako sa podmienky budú meniť v čase. K dispozícii má len 2 údaje.

  • dĺžku (D) jeho cesty
  • zoznam (Z) súradníc (S), na ktorých sa cestou nachádzajú stromy

Formát vstupov

Dĺžka D je kladné celé číslo. Súradnica S je kladné celé číslo, ktoré udáva, vo vzdialenosti koľkých metrov od štartu sa nachádza strom. S < D, S >= 0.

@peterkracik
peterkracik / mysql57.sql
Last active April 16, 2019 07:57
MYSQL 5.7: group by error
set session sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
set global sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';