Skip to content

Instantly share code, notes, and snippets.

View Kamilnaja's full-sized avatar
💭
🐍🔥

Kamil Naja Kamilnaja

💭
🐍🔥
View GitHub Profile
const fs = require('fs');
let rawData = fs.readFileSync('data.json');
let data = JSON.parse(rawData);
const convertToNumber = item => {
item.workTimeRangeSum = Number(item.workTimeRangeSum.split(':').join('.').replace(/\.3/g, '.5'));
return item;
}
const res = data.workDays
.map(item => {
// so, you have list of users like this
const users = [
{ id: '1', name: 'hello' },
{ id: '2', name: 'world' },
{ id: '3', name: 'hello' },
{ id: '1', name: 'hello' },
{ id: '1', name: 'hello' },
]
@Kamilnaja
Kamilnaja / count.ts
Created August 17, 2019 07:33
Programming exercise #12 Count, how many certain items exists in array of objects.
// So, you have input data like this
let objArr = [
{ id: 1, name: 'Kamil' },
{ id: 2, name: 'Janusz' },
{ id: 3, name: 'Mariusz' },
{ id: 4, name: 'Alina' },
{ id: 5, name: 'Olo' } ];
// I think, that this is an interesting answer. Check if object key exists, if yes, double
const columns = [
{ name: 'one', title: 'Order Number', id: 1 },
{ name: 'two', title: 'Strawberry', id: 2 },
{ name: 'three', title: 'Vanilla', id: 3 }
];
const mapped = columns.map(
item => item.id ? item.id = item.id * 2 : item
@Kamilnaja
Kamilnaja / type.ts
Created June 12, 2019 18:48
Typescript - type for HTMLElementEvent
type HTMLElementEvent<T extends HTMLElement> = Event & {
target: T;
}
let res = allEvents$.subscribe((item: HTMLElementEvent<HTMLButtonElement>) => {
console.log(item.target.value);
})
@Kamilnaja
Kamilnaja / filter.ts
Created April 24, 2019 18:30
Filter data from object array and return as array
import { from } from "rxjs";
import { filter, reduce } from "rxjs/operators";
let candidates = [
{ name: 'Brendan Eich', experience: 'JavaScript Inventor' },
{ name: 'Emmet Brown', experience: 'Historian' },
{ name: 'George Lucas', experience: 'Sci-fi writer' },
{ name: 'Alberto Perez', experience: 'Zumba Instructor' },
{ name: 'Bjarne Stroustrup', experience: 'C++ Developer' }
];
@Kamilnaja
Kamilnaja / decorator.ts
Created April 8, 2019 18:03
Decorator pattern implementation in ts
abstract class Beverage {
description: string = "unknown beverage";
public getDescription(): string {
return this.description;
}
public abstract cost(): number;
}
abstract class CondimentDecorator extends Beverage {
abstract getDescription(): string;
@Kamilnaja
Kamilnaja / strategy.ts
Created April 6, 2019 09:47
strategy implementation in ts
class Knight {
constructor(private name: string, private age: number) { }
public getAge(): number {
return this.age;
}
public getName(): string {
return this.name;
}
@Kamilnaja
Kamilnaja / angular.component.spec.ts
Created March 24, 2019 12:30
Angular test component with mock service, that uses http
import { async, TestBed } from '@angular/core/testing';
import { Observable, of } from 'rxjs';
import { AppComponent } from './app.component';
import { HerbsService } from './herbs.service';
import { RouterTestingModule } from '@angular/router/testing';
class MockService {
mockRespone = {
data: [
{ id: 1, name: 'hello' },
@Kamilnaja
Kamilnaja / gist:e510241810f005b8bd7bde5e39c2f67a
Created February 22, 2019 23:47
Python_do_something_with_every_second.py
string = "How good is have account on StackOverflow and create new posts"
def odd(data):
idx, el = data
return el if idx % 2 == 0 else el + "\n"
print(" ".join(list(map(odd, list(enumerate(string.split(" ")))))))