View string-to-color.js
function hashCode(str) { | |
var hash = 0; | |
for (var i = 0; i < str.length; i++) { | |
hash = str.charCodeAt(i) + ((hash << 5) - hash); | |
} | |
return hash; | |
} | |
function intToRGB(i) { | |
const c = (i & 0x00ffffff).toString(16).toUpperCase(); |
View ng-for-filter.pipe.ts
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'ngForFilter', | |
pure: false, | |
}) | |
export class NgForFilterPipe implements PipeTransform { | |
isStrict: boolean; | |
transform( |
View object.ts
export function getKeyByValue(structure: object, value: string | number) { | |
return Object.keys(structure).find((keyItem: keyof object) => structure[keyItem] === value); | |
} |
View files-over-http.service.ts
import { Injectable } from '@angular/core'; | |
import { | |
HttpClient, | |
HttpEvent, | |
HttpEventType, | |
HttpHeaders, | |
} from '@angular/common/http'; | |
import { Observable } from 'rxjs'; | |
import { map } from 'rxjs/operators'; | |
import { defaults } from 'lodash'; |
View ajax_request.ts
export interface FileUploadSchema { | |
done: boolean; | |
response: string; | |
status: number; | |
progress: number; | |
} | |
export class Request { | |
request(method: string, URL: string, body: any) { | |
return new Observable<FileUploadSchema>(subscriber => { |
View treeflat.ts
export interface DisassembledTreeNodeSchema { | |
index: string; | |
} | |
export interface TreeNodeItem { | |
value: DisassembledTreeNodeSchema; | |
children: TreeNodeItem[]; | |
} | |
const tree: TreeNodeItem[] = [nested tree data]; |
View counter.js
// First example | |
function Counter () { | |
let val = 0; | |
return function () { | |
return ++val; | |
} | |
} | |
const b = new Counter(); |
View utils.ts
export class Utils { | |
/** | |
* @static | |
* @param {*} value | |
* @param {*} [strict=false] | |
* @returns {boolean} | |
* @memberof Utils | |
* | |
* Under the rule of strict the values of object and arrays will be checked as well | |
* Also Number 0 under strict will return false |
View ifile.to.file.ts
export class Helpers { | |
// For some reason uploading files from ionic image picker sometimes loses type and sets it to plain/text | |
// This basically is a hack but works well | |
IFlieToFile(file: any): Promise<File> { | |
return new Promise((resolve, reject) => { | |
if (file.localURL === undefined) { | |
return resolve(<File> file); | |
} | |
let fr = new FileReader(); | |
fr.readAsArrayBuffer(file); |
View refresh-image.js
var image = $('#mainImageFeature'); | |
if( image.length > 0 ){ | |
var displayed = 0; | |
$(window).on("scroll",function(){ | |
console.log(document.body.scrollTop + ' = ' + image.offset().top); | |
if(document.body.scrollTop < image.offset().top + image.height()){ | |
if(displayed == 0){ | |
image.attr('src',image.attr('src')); | |
displayed = 1; |
NewerOlder