Skip to content

Instantly share code, notes, and snippets.

View dinhchuong7913's full-sized avatar
🎯
Focusing

dinhchuong7913 dinhchuong7913

🎯
Focusing
View GitHub Profile
@dinhchuong7913
dinhchuong7913 / gist:6dce3cce1fc53fbdff3f1caff7ab2723
Created September 16, 2019 03:42 — forked from vargeorge/gist:3841988
Mysql2 gem installation on OS X with MAMP installed
Use the following steps if you are looking to reuse MAMP mysql install for your rails app. This is how I set my machine. Hope its useful to others.
Steps:
1. Download mysql source code for the mysql version in your MAMP installation.
a. Find your MAMP version
$ system_profiler SPApplicationsDataType | grep -B5 "MAMP" | awk '/Version/ { print $2 }'
b. Find your MAMP mysql component version
Go to http://www.mamp.info/en/documentation/releases.html to find mysql component
@dinhchuong7913
dinhchuong7913 / php-lint-pre-commit.sh
Created May 30, 2019 09:40 — forked from filipekiss/php-lint-pre-commit.sh
A *really* simple git pre-commit-hook that lints all staged PHP files.
#!/bin/bash
stagedFiles=$(git diff-index --cached HEAD | grep ".php" | grep "^:" | sed 's:.*[DAM][ \\''t]*\([^ \\''t]*\):\1:g');
phpLintErrors=0
echo "PHP will now lint all the php staged files..."
echo ""
for file in $stagedFiles
do
echo "PHP is linting $file...";
echo ""
php -l $file
@dinhchuong7913
dinhchuong7913 / example-virtual-host.ssl.test.conf
Created January 25, 2019 09:04 — forked from ankurk91/example-virtual-host.ssl.test.conf
Sample virtual host .conf file for Apache2 on Ubuntu
# This to be used when you need to implement SSL
# Make sure that apache mod_ssl is on
# You can generate self signed certificates for development
# http://www.selfsignedcertificate.com/
<VirtualHost *:443>
ServerName yourapp.test
#ServerAlias www.yourapp.test
StoredProcedureQuery q = this.em.createNamedStoredProcedureQuery(“getReviews”);
q.setParameter(2, b.getId());
List<Review> reviews = q.getResultList();
@dinhchuong7913
dinhchuong7913 / Install nginx + PHP 7.1 on CentOS 7
Created July 20, 2018 08:06
CentOS 7, nginx, PHP 7.1 Configuration
Step by step installation guide for nginx + PHP 7.1 on CentOS 7
1. Add and enable Remi repos
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --enable remi-php71
2. Install php 7.1 and required modules
yum install php71-php-fpm
@dinhchuong7913
dinhchuong7913 / 1-Overview.md
Created April 27, 2018 11:31 — forked from dsteiner93/1-Overview.md
Default method parameters in Java

Java does not offer default method parameters like many languages do. While there are some inelegant workarounds ([see this stack overflow thread for details][stack]) design patterns are no substitute for the simplicity of Python (and most other languages') default parameter syntax:

def method(a, b, c=1, d=1):
  return a+b+c+(2*d)

method(1, 1) # Returns 5
method(1, 1, d=2) # Returns 7
@dinhchuong7913
dinhchuong7913 / simple-pagination.js
Created April 11, 2018 08:04 — forked from kottenator/simple-pagination.js
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@dinhchuong7913
dinhchuong7913 / Laravel requires the Mcrypt PHP extension
Created September 26, 2017 18:11 — forked from alexlondon07/Laravel requires the Mcrypt PHP extension
Change default Mac OS X PHP to MAMP's PHP Installation
Change default Mac OS X PHP to MAMP's PHP Installation
Instructions to Change PHP Installation
First, Lets find out what version of PHP we're running (To find out if it's the default version).
To do that, Within the terminal, Fire this command:
which php
@dinhchuong7913
dinhchuong7913 / ckeditor-responsive-images.js
Created August 29, 2017 17:06 — forked from fabiomaggio/ckeditor-responsive-images.js
Make inserted images in CKEditor automatically responsive
// If you want inserted images in a CKEditor to be responsive
// you can use the following code. It creates a htmlfilter for the
// image tag that replaces inline "width" and "style" definitions with
// their corresponding attributes and add's (in this example) the
// Bootstrap "img-responsive" class.
CKEDITOR.on('instanceReady', function (ev) {
ev.editor.dataProcessor.htmlFilter.addRules( {
elements : {
img: function( el ) {
// Add bootstrap "img-responsive" class to each inserted image