This file contains 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 {Pipe, PipeTransform} from '@angular/core'; | |
@Pipe({ | |
name: 'dateAgo', | |
pure: true | |
}) | |
export class DateAgoPipe implements PipeTransform { | |
transform(value: any, args?: any): any { | |
if (value) { |
This file contains 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 { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'shortNumber' | |
}) | |
export class ShortNumberPipe implements PipeTransform { | |
transform(number: number, args?: any): any { | |
if (isNaN(number)) return null; // will only work value is a number | |
if (number === null) return null; |
This file contains 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 { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'shortDomain' | |
}) | |
export class ShortDomainPipe implements PipeTransform { | |
transform(url: string, args?: any): any { | |
if (url) { | |
if (url.length > 3) { |
This file contains 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 { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'shortDomain' | |
}) | |
export class ShortDomainPipe implements PipeTransform { | |
transform(url: string, args?: any): any { | |
if (url) { | |
if (url.length > 3) { |
This file contains 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 { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'shortUrl' | |
}) | |
export class ShortUrlPipe implements PipeTransform { | |
transform(url: string, args?: any): any { | |
if (url) { | |
const len = url.length; |
This file contains 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
print("Hello, World!") |
This file contains 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
x = 1 | |
if x == 1: | |
# indented four spaces | |
print("x is 1.") |
This file contains 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
my_var = 7 | |
print(my_var) | |
my_var = 7.0 | |
print(my_var) | |
my_var = int(my_var) # casting | |
print('int again:', my_var) | |
my_var = 'hello' |
This file contains 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
a, b, c = 3, 4, 'Max' | |
print(a, b, c) |
This file contains 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
mylist = [] | |
mylist.append(1) | |
mylist.append(2) | |
mylist.append(3) | |
print(mylist[0]) # prints 1 | |
print(mylist[1]) # prints 2 | |
print(mylist[2]) # prints 3 | |
# prints out 1,2,3 |
OlderNewer