Skip to content

Instantly share code, notes, and snippets.

View msarsha's full-sized avatar
🏠
Working from home

Matan Sar-Shalom msarsha

🏠
Working from home
View GitHub Profile
@msarsha
msarsha / timers.ts
Last active September 9, 2021 20:41
timers
// useTimer.tsx
function useTimer(timer: Timer) {
const { dispatch } = useContext(TimersContext);
const timeoutRef = useRef<number>();
useEffect(() => {
if (timer.done || timer.paused) {
cleanUp();
timeoutRef.current = 0;
} else {
export class MyComponent {
polling$ = interval(60000);
data$ = this.service.getData();
dataPolling$ = this.polling$.pipe(
switchMap(() => this.data$)
);
//Now you have two options, either .subscribe() in the constructor or use the async pipe
storeList$: Observable<Map<string,number>>;
stores$: Observable<string[]>;
ngOnInit() {
this.stores$ = this.itemsQuery.selectAll().pipe(map(entities =>
entities.map(entity => entity.store)
// .filter((elem, index, self) => {
// return index === self.indexOf(elem);
// })
));
getRate() {
this.items$ = this.service.getConversion()
.pipe(
tap((data) => {this.conversionRate = data.rates.USD;}),
switchMap(() => this.createItemsObservable())
)
}
private createItemsObservable(): Observable<Item[]>{
return this.itemsQuery.selectAll()
const createRequestTwo(data): Observable<any>{
return this.http.post(url, data);
}
return requestOne
.pipe(
switchMap(
(requestOneResult) => {return createRequestTwo(requestOneResult)}
)
).subscribe((requestTwoResult) => {...})
// --------
const singleTree = {
branches: [],
operation: null,
value: {
dataSource: 'customer props',
fieldOrFunc: 'installation date',
operation: {
name: 'between',
@msarsha
msarsha / tree.ts
Created January 22, 2020 09:57
tree
// --------
const singleTree = {
branches: [],
operation: null,
value: {
dataSource: 'customer props',
fieldOrFunc: 'installation date',
operation: {
name: 'between',
@msarsha
msarsha / tree.ts
Created January 22, 2020 09:57
tree
// --------
const singleTree = {
branches: [],
operation: null,
value: {
dataSource: 'customer props',
fieldOrFunc: 'installation date',
operation: {
name: 'between',
@msarsha
msarsha / hooks.md
Created October 18, 2019 13:34
Setting up git hooks with husky, commitlint and prettier
  1. npm install prettier --save-dev --save-exact

  2. npx mrm lint-staged

  3. npm install --save-dev @commitlint/{cli,config-conventional}

  4. echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js

  5. edit package.json:

  "husky": {
    "hooks": {
<div class="m-2">
<div class="search-container">
<input #searchInput pattern="[A-Za-z]" class="search-input" type="text"
(keyup.enter)="validInput && onSearch(searchInput.value)" placeholder="search city"
(change)="checkValues(searchInput.value)"> <i
class="fas fa-search-location search-icon" (click)="validInput && onSearch(searchInput.value)"></i>
</div>
<ng-container *ngIf="(weatherData$ | async).main as weatherData; else noDataMessage">
<div class="d-flex">