Skip to content

Instantly share code, notes, and snippets.

View akwodkiewicz's full-sized avatar

Andrzej Wódkiewicz akwodkiewicz

View GitHub Profile
@akwodkiewicz
akwodkiewicz / some-time-ago.js
Created January 29, 2023 11:43
Distance from given date in "X days/weeks/months ago" format using Intl
/**
* Tells you how long ago was `inputDate` in "x days/weeks/months ago" format using `Intl`
* ({@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl docs}).
* Automatically changes the resolution from days, to weeks, to months, to keeps things readable.
* Returns the exact date if the `inputDate` happened very long time ago.
*
* Dates only, time is ignored.
*
* You can use `forcedLocale` to get the string in a specific locale, otherwise a browser locale
* is used.
@akwodkiewicz
akwodkiewicz / scratchpad.ts
Last active December 20, 2021 12:15
Handy TS/JS functions
// Group elements in `xyz` array in `groupSize`-length arrays
const xyz = ['a','b','c','d','e','f','g','h','i'];
const groupSize = 3;
xyz.reduce<string[][]>((result, item, idx) =>
new Boolean((idx % groupSize
? result[result.length-1].push(item)
: result.push([item])))
&& result,
[]);
@akwodkiewicz
akwodkiewicz / nest-node-repl.js
Created November 6, 2020 13:27
NestJs in node REPL
// For this trick you'll need:
//
// $ node --experimental-repl-await
//
// If you happen to use Typescript alias paths, you'll also want to install `tsconfig-paths`
// and actually run the node REPL with:
//
// $ TS_NODE_PROJECT=path/to/tsconfig.json node -r tsconfig-paths/register --experimental-repl-await
//
// All the statements need to be input inside REPL.
@akwodkiewicz
akwodkiewicz / polona.py
Last active March 28, 2018 23:02
Quick usage of Polona API
import requests
from pprint import pprint
base_url = 'https://polona.pl/api/'
entities = 'entities/?format=json'
filters = '&filters=category:serials+public:1+has_text_content:1+language:polski'
seed = '&seed=8'
size = '&size=45'
resp = requests.get(base_url + entities + size + seed + filters)
import os
import requests
import qrcode
from PIL import Image
from bs4 import BeautifulSoup
BASE_URL = 'https://easyweb.workshop.codisec.com'
TEMPLATE_IMG = 'template.png'
USER = 'andrzej'
PASSWORD = 'andrzej'
@akwodkiewicz
akwodkiewicz / AbstractSdmFactory.groovy
Last active September 1, 2017 20:06
Problem skryptowy
public abstract class AbstractSdmFactory {
private final String url
private final long rfcId
private final long reqId
public Ticket createTicket(long issueTypeId, LinkedHashMap attributes) {
if (this.rfcId == issueTypeId) {
return new Rfc('attributes': attributes)
} else if (this.reqId == issueTypeId) {
return new Request('attributes': attributes)
public static Tuple<Point, Point> FindClosestPoints(List<Point> points, out double minDistance)
{
var minDist = double.PositiveInfinity;
int lastDeleted = 0;
Point a = new Point();
Point b = new Point();
SortedSet<Point> tree = new SortedSet<Point>(new ByY());
var pointsArray = points.ToArray();
Array.Sort(pointsArray, new ByX());
@akwodkiewicz
akwodkiewicz / pipes.c
Last active March 16, 2017 08:16
Rozwiązanie zadania 1_2B z SOP2
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/wait.h>
#include <string.h>