Skip to content

Instantly share code, notes, and snippets.

@DanielKucal
DanielKucal / command.md
Last active December 24, 2023 05:34
Run `sam local start-api` watching for changes in TypeScript source files

Run sam local start-api watching for changes in TypeScript source files

sam build && concurrently "nodemon --on-change-only --ext ts --exec sam build" "sam local start-api"

Requires npm i -g nodemon concurrently

It runs nodemon and sam local start-api in the background simultaneously. The trick is to have the build available before creating docker image, so it's done beforehand and nodemon does it only after changes (using --on-change-only flag).

@DanielKucal
DanielKucal / Angular sanitizer pipes.ts
Created December 23, 2022 18:59
safeHtml, safeStyle, safeScript, safeUrl and safeResourceUrl pipes included in a SafeResourceModule
import { CommonModule } from '@angular/common';
import { Injectable, NgModule, Pipe, PipeTransform } from '@angular/core';
import {
DomSanitizer,
SafeHtml,
SafeResourceUrl,
SafeScript,
SafeStyle,
SafeUrl,
} from '@angular/platform-browser';
@DanielKucal
DanielKucal / sort CSV columns by header.ts
Created April 3, 2018 21:25
Sort input from CSV file by header in TypeScript
export class Challenge {
public static sortCsvColumns (csv_data: string): string {
const rows = csv_data.split('\n').map(row => row.split(','));
const data: CsvData = {};
for (const row of rows) {
for (let i = 0; i < row.length; i++) {
const header = rows[0][i].toLowerCase();
if (!data[header]) {
data[header] = [];
} else {
@DanielKucal
DanielKucal / Fastlint.md
Last active March 24, 2021 05:16
Run tslint in pre-commit with good performance and auto fixer

Fast lint with autofixer

for pre-commit hook

In order to run linter in a pre-commit hook you can check changed files only for performance reasons.

package.json:

{
  "scripts": [
    "fastlint": "git diff --cached --name-only | grep .ts$ |  xargs -L1 \"./node_modules/.bin/tslint\" --fix"
 ],
# Created by https://www.gitignore.io/api/macos,jetbrains+all
### JetBrains+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
var net = require("net");
var server = net.createServer();
var users = [];
var tools = require("./tools")(users);
server.on('connection', function (conn) {
conn.setEncoding("utf8");
conn.write("Hello, what's your name?\r\n");
users.push(conn);
/**
* Sum all odd Fibonacci Sequence elements less than given number
* Return the sum of all odd Fibonacci numbers up to and including the passed number if it is a Fibonacci number.
*/
function sumOddFibs(num) {
var sum = 0;
var fibs = [1, 1];
while (Math.max.apply(Math, fibs) < num) {
fibs.push(fibs[fibs.length-1]+fibs[fibs.length-2]);
function arabic2roman(num) {
var romans = {
0: {"key": 1, "value": "I"},
1: {"key": 4, "value": "IV" },
2: {"key": 5, "value": "V"},
3: {"key": 9, "value": "IX"},
4: {"key": 10, "value": "X"},
5: {"key": 40, "value": "XL"},
6: {"key": 50, "value": "L"},
7: {"key": 90, "value": "XC"},
function mySort(array $elements) {
$sorted = true;
for ($i = 0; $i < count($elements)-1; $i++) {
if ($elements[$i] > $elements[$i+1]) {
$tmp = $elements[$i+1];
$elements[$i+1] = $elements[$i];
$elements[$i] = $tmp;
$sorted = false;
}