Skip to content

Instantly share code, notes, and snippets.

View tnqsoft's full-sized avatar

Tuấn Quỳnh Software tnqsoft

View GitHub Profile
@tnqsoft
tnqsoft / TreeChoiceType.php
Last active April 11, 2017 18:13
EntityType Tree Display For Symfony 3
<?php
namespace CommonBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormView;
@tnqsoft
tnqsoft / TreeChoiceType-V2.php
Created April 11, 2017 18:27
EntityType Tree Display For Symfony 3 - Version 2
<?php
namespace CommonBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormView;
@tnqsoft
tnqsoft / math-lession-1.php
Created April 27, 2017 22:40
Code snippet with math lession
<?php
/**
* Code snippet with math lession
* @author Nguyen Nhu Tuan <tuanquynh0508@gmail.com>
*/
// 2^3 = 8
echo getExponential(2, 3);
echo '<br/>';
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser';
/*
* Trust pipe
* Usage:
* value | safe
*/
@Pipe({
name: 'safe'
@tnqsoft
tnqsoft / angular2-http-audio.ts
Last active June 14, 2017 07:47
Angular 2 HTTP Audio
import { Response, RequestOptions, Headers, ResponseContentType } from '@angular/http';
import * as FileSaver from 'file-saver';
/**
* Get Audio
*
* @returns {Promise<Blob>}
*/
public getAudio(): Promise<Blob> {
let url = `http://example.com/demo.wav`;
.long-text {
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP printers */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
word-wrap: break-word; /* IE */
word-break: break-all;
}
@tnqsoft
tnqsoft / long-file-name.pipe.ts
Created July 11, 2017 04:05
Angular 4 Long file name
import { Pipe, PipeTransform } from '@angular/core';
/*
* Format long file name
* Max length, default is 100
* Usage:
* filename | longFileName:maxLength
* Example:
* {{ 'demo file name long at here, this is long file name omg please try input now.txt' | longFileName:40}}
* formats to: demo file name long ...se try input now.txt
@tnqsoft
tnqsoft / human-file-size.pipe.ts
Created July 11, 2017 04:06
Angular 4 Human file size in English
import { Pipe, PipeTransform } from '@angular/core';
/*
* Convert bytes into largest possible unit.
* Takes an precision argument that defaults to 2.
* Usage:
* bytes | humanFileSize:precision
* Example:
* {{ 1024 | humanFileSize}}
* formats to: 1 KB
@tnqsoft
tnqsoft / example.html
Last active June 29, 2024 14:09
Preview image for ng2-file-upload
<div *ngFor="let item of uploader.queue; let first = first;">
<img src="" thumbnail [image]="item?._file"/>
{{ item?.file?.name }}
{{ item?.file?.size }}
</div>
<input type="file" ng2FileSelect [uploader]="uploader" #fileInput [accept]="accept.toString()" [multiple]="multiple"/>
@tnqsoft
tnqsoft / app.module.ts
Last active August 24, 2017 07:25
Angular 4 with ng2-file-upload
import { FileUploadModule } from 'ng2-file-upload';
import { ThumbnailDirective } from './thumbnail.directive';
...
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
CommonModule,
FileUploadModule
],