This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This resolver forces Jest to look at a *custom* `"jest"` condition in `package.json#exports`. | |
* | |
* Whenever you use self-referencing imports or subpath imports in the source code (or tests) | |
* the default behaviour of Jest is to go to the package's manifest for information, and resolve | |
* the import by choosing one of the conditions that are used by Node ("node", "default", etc.). | |
* | |
* The issue is that "node"/"default" usually points to transpiled `.js` files, whereas if you decide to | |
* run the tests on the `.ts` source code (with the help of a transformer such as ts-jest or @swc/jest), | |
* you need Jest to **only** load the `.ts` files. Otherwise, you end up with duplicated classes, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, | |
[]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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> |