Skip to content

Instantly share code, notes, and snippets.

View hungtrinh's full-sized avatar

Hưng Trịnh hungtrinh

  • Ha Noi, Viet Nam
  • 10:27 (UTC +07:00)
View GitHub Profile
@hungtrinh
hungtrinh / composer.md
Created May 21, 2020 14:56 — forked from xeoncross/composer.md
How composer actually works

Composer

the missing quick-start guide

We will assume we have a package/project called https://github.com/foo/bar

Most redistributable packages are hosted on a version control website such as Github or Bitbucket. Version control repositories often have a tagging system where we can define stable versions of our application. For example with git we can use the command:

git tag -a 1.0.0 -m 'First version.'

With this we have created version 1.0.0 of our application. This is a stable release which people can depend on. If we wanted to include "foo/bar" then we could create a composer.json and specify the tagged release we wanted:

@hungtrinh
hungtrinh / .gitlab-ci.yml
Created May 12, 2020 10:39 — forked from jlis/.gitlab-ci.yml
AWS ECS and ECR deployment via Docker and Gitlab CI
image: docker:latest
variables:
REPOSITORY_URL: <AWS ACCOUNT ID>.dkr.ecr.eu-central-1.amazonaws.com/<ECS REPOSITORY NAME>
REGION: eu-central-1
TASK_DEFINTION_NAME: <TASK DEFINITION NAME>
CLUSTER_NAME: <CLUSTER NAME>
SERVICE_NAME: <SERVICE NAME>
services:
@hungtrinh
hungtrinh / Export CSV.php
Created July 24, 2019 03:01 — forked from SimonEast/Export CSV.php
PHP Example: Stream a CSV File to Browser with GZIP Compression (exporting from MySQL/PDO)
<?php
/**
* This script performs a full dump of a database query into
* CSV format and pipes it directly to the browser.
*
* - YES, the browser will save the CSV file to disk
* - YES, it should support large files without using massive amounts of memory
* - YES, it compresses the request using GZIP to reduce download time
*/
@hungtrinh
hungtrinh / CorsMiddlewareFactory.php
Created June 20, 2019 02:41 — forked from akrabat/CorsMiddlewareFactory.php
Expressive factory to use CORS middleware
<?php declare(strict_types=1);
namespace App\Factory;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Tuupola\Middleware\Cors;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\JsonResponse;
use Zend\ProblemDetails\ProblemDetailsResponseFactory;
use Zend\Stratigility\Middleware\CallableMiddlewareWrapper;
@hungtrinh
hungtrinh / index.jsx
Created March 15, 2019 09:25 — forked from avinmathew/index.jsx
Multiple layouts with React Router v4
import React from "react"
import { Route, Switch } from "react-router-dom"
const AppRoute = ({ component: Component, layout: Layout, ...rest }) => (
<Route {...rest} render={props => (
<Layout>
<Component {...props} />
</Layout>
)} />
)
@hungtrinh
hungtrinh / introrx.md
Created February 26, 2019 17:32 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@hungtrinh
hungtrinh / bitwise-permission-checking.php
Created April 10, 2018 07:00
Check permission using bitwise operators
Initially, I found bitmasking to be a confusing concept and found no use for it. So I've whipped up this code snippet in case anyone else is confused:
<?php
// The various details a vehicle can have
$hasFourWheels = 1;
$hasTwoWheels = 2;
$hasDoors = 4;
$hasRedColour = 8;
@hungtrinh
hungtrinh / pre-commit
Created March 7, 2017 10:23 — forked from mklabs/pre-commit
run jshint as git/hg hooks, NO COMMIT IF NO LINT FREE.
#!/usr/bin/env node
// todo: try to require jshint here, instead of spawning process, then fallback to spawning process.
var jshint = nrequire('jshint');
if (jshint) return process.exit(0);
// jshint not installed locally, spawn process instead.
// basically the same, but less pretty.
var exec = require('child_process').exec;
@hungtrinh
hungtrinh / Vagrantfile
Created March 1, 2017 13:21
Vagrant configuration file with OS detection - on windows we mount shared folders without NFS - on all other OS we use NFS for speeding up the project inside the virtual machine
# -*- mode: ruby -*-
# vi: set ft=ruby :
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
@hungtrinh
hungtrinh / regex-japanese.txt
Created January 17, 2017 03:29 — forked from terrancesnyder/regex-japanese.txt
Regex for Japanese
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)