Skip to content

Instantly share code, notes, and snippets.

View piotrekwitkowski's full-sized avatar

piotrekwitkowski

View GitHub Profile
@piotrekwitkowski
piotrekwitkowski / redirect-behavior.ts
Last active February 14, 2024 22:38
Redirect behavior for CloudFront with CDK and TypeScript
import { Stack } from "aws-cdk-lib";
import { BehaviorOptions, Function, FunctionCode, FunctionEventType } from "aws-cdk-lib/aws-cloudfront";
import { HttpOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
import { join } from "path";
export const getRedirectBehavior = (scope: Stack, id: string, location: string): BehaviorOptions => {
const redirectFilePath = join(__dirname, 'redirect-function.js');
const redirectFunctionCode = FunctionCode.fromFile({ filePath: redirectFilePath });
const redirectFunction = new Function(scope, `${id}-default-redirect-function`, {
code: redirectFunctionCode
@piotrekwitkowski
piotrekwitkowski / with-delay.ts
Created August 1, 2023 10:52
Typescript HOC withDelay
const withDelay = async <T,>(delay = 0, callback: () => T) => {
await new Promise(resolve => setTimeout(resolve, delay));
return callback();
}
@piotrekwitkowski
piotrekwitkowski / user-data.sh
Last active July 20, 2023 18:44
User Data script for EC2 to clone and run node app with pm2
#!/bin/bash
sudo yum update -y
sudo yum install -y git nodejs
git -v # Check git version
node -v # Check node version
npm -v # Check npm version
npm i -g pm2
export HOME=/home/ec2-user
pm2 -v # Check pm2 version
@piotrekwitkowski
piotrekwitkowski / gitlab-mirroring-template.yaml
Last active January 27, 2023 15:58
GitLab to CodeCommit code mirroring template
AWSTemplateFormatVersion: 2010-09-09
Description: |
Gitlab mirroring to AWS CodeCommit
Parameters:
CreateCodeCommitRepository:
Description: Would you like to create a new CodeCommit repository?
Type: String
Default: 'create-new'
@piotrekwitkowski
piotrekwitkowski / Component.ts
Created October 12, 2019 02:02
Loading scss files in typescript using webpack
import { LitElement, html, customElement, property } from "lit-element";
import style from "./Style";
@customElement('my-component')
class MyComponent extends LitElement {
static styles = style;
render() {
return html`<p>Styled component</p>`;
### Task 2
png(filename = "HistogramExams.png")
hist(
exam,
# breaks=seq(from=1.0, to=5.0, by=0.1),
breaks = c(0, 0.3, 0.7, 1.0, 1.3, 1.7, 2.0, 2.3, 2.7, 3.0, 3.3, 3.7, 4.0, 4.3, 4.7, 5.0),
xlim = c(0, 5),
freq = TRUE,
xlab="Grades",
### Task 10
iterative_sum <- function (n) {
sum <- 0
for (i in 1: n) {
sum = sum + i
}
return(sum)
}
recursive_sum <- function (n) {
@piotrekwitkowski
piotrekwitkowski / app-layout.js
Created February 22, 2019 22:55
Użycie Sass/CSS w customElmentach przy użyciu lit-element i webpacka (3)
import { css } from 'lit-element'; //nie zapomnij o zaimportowaniu dyrektywy
import style from './app-layout.scss'
class AppLayout extends LitElement {
static get styles() {
return [
css([style]),
];
}
@piotrekwitkowski
piotrekwitkowski / webpack.config.js
Created February 22, 2019 22:47
Użycie Sass/CSS w customElmentach przy użyciu lit-element i webpacka (2)
module: {
rules: [
{
test: /\.scss$/,
use: [
'css-loader',
{
loader: 'sass-loader',
options: { includePaths: ['./node_modules'] } //prawdopodobnie potrzebujesz tego, jeśli korzystasz z dalszych bibliotek, jak np. Material Design
}
@piotrekwitkowski
piotrekwitkowski / package.json
Created February 22, 2019 22:43
Użycie Sass/CSS w customElmentach przy użyciu lit-element i webpacka (1)
"devDependencies": {
"css-loader": "^2.1.0",
"lit-element": "^2.0.1",
"node-sass": "^4.11.0",
"sass-loader": "^7.1.0",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1"
}