Skip to content

Instantly share code, notes, and snippets.

View algotrader-dotcom's full-sized avatar

Mai_Xoa algotrader-dotcom

View GitHub Profile
@algotrader-dotcom
algotrader-dotcom / Git and Github in 5 minutes
Last active July 28, 2021 06:41
Git and Github in 5 minutes
# Git and Github in 5 minutes
1. First of all, you need to create a git project like this:
git init learn-git
cd learn-git
Then, once you are in a git repository, you start writing the initial draft of the code.
file: helloword.php
<?php echo "Hello World!\n"; ?>
@algotrader-dotcom
algotrader-dotcom / Ansible Kickstart
Last active October 21, 2021 23:08
Ansible Kickstart
##What's 'Ansible' ?
Ansible is configuration management tool like SaltStack, Puppet but it works through SSH, no need to install agent on managed nodes.
##Why's Ansible ?
As my point, i love ansible for:
- No need to install agent on agent nodes
##How's Ansible?
### Install Ansible on master node
@algotrader-dotcom
algotrader-dotcom / AWS EC2 Instance Metadata
Created October 14, 2015 04:25
AWS EC2 Instance Metadata
There is an easy way to access to Instance information from within
# Obtaining the Instance ID:
wget -q -O - http://169.254.169.254/latest/meta-data/instance-id
i-87eef4e2
# Public Hostname:
wget -q -O - http://169.254.169.254/latest/meta-data/public-hostname
ec2-50-17-85-234.compute-1.amazonaws.com
@algotrader-dotcom
algotrader-dotcom / yum update exclude certain package
Last active October 29, 2015 06:19
yum update exclude certain package
yum --exclude php*,httpd*,kernel* update
@algotrader-dotcom
algotrader-dotcom / Nginx rewrite url to php backend app
Created October 18, 2015 17:49
Nginx rewrite url to php backend app
#
# This rewrite http://domain.com/dl/121/abc.pdf to PHP as http://domain.com/dl.php?nid=121&url=abc.pdf
#
server {
...
location /dl {
rewrite ^/dl/(.*)/(.*)$ /dl.php?nid=$1&url=$2 last;
break;
}
...
@algotrader-dotcom
algotrader-dotcom / Solarium PHP client configuration
Last active October 19, 2015 10:50
Solarium PHP client configuration
# Install Solarium-Client
$ yum install composer
$ vi composer.json
{
"require": {
"solarium/solarium": "2.4.0"
}
}
$ composer install
@algotrader-dotcom
algotrader-dotcom / Drupal 7: Snippet codes get related articles with Solr
Last active November 5, 2015 14:19
Drupal 7: Snippet codes get related articles with Solr MLT
@algotrader-dotcom
algotrader-dotcom / Drupal 7: Add custom field indexed in Apache Solr
Last active October 20, 2015 15:06
Drupal 7: Add custom field indexed in Apache Solr
...
function mymodule_apachesolr_index_document_build_node(ApacheSolrDocument $document, $entity, $env_id) {
if ($entity->type == 'company'){
$node_field_address = $entity->field_address['und'][0]['value'];
// Add the image and description to the document in the solr index.
$document->addField('ts_company_add', $node_field_address);
}
}
...
@algotrader-dotcom
algotrader-dotcom / Drupal 7 Page Template
Created October 27, 2015 04:33
Drupal 7 Page Template
# Basic page with ID 123
page--node--123.tpl.php
# Frontpage
page--front.tpl.php
# Default
page.tpl.php
@algotrader-dotcom
algotrader-dotcom / Drupal 7 : Update taxonomy term programmatically
Last active October 27, 2015 07:13
Drupal 7 : Update taxonomy term programmatically
<?php
define('DRUPAL_ROOT', '/home/vhosts/domain.com');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once( DRUPAL_ROOT . '/sites/all/libraries/simplehtmldom/simple_html_dom.php');
include("phpcrawler/libs/PHPCrawler.class.php");
set_time_limit(0);
$vid = 10; // Category