snippets GIT - 子模块

GIT - 子模块

command_line2.snippets
#UPDATES ALL SUBMODULES
#In Main project

#If its the first time:
git submodule update --init --recursive

#If not
git submodule foreach git pull origin master
command_line.snippets
#COMMIT AND PUSH ALL SUBMODULES
#In Main project

git submodule foreach 'git add .' #recursively add files in submodules
git submodule foreach 'git commit -a -m "Altered submodule" || :'
git add --all :/
git commit -am "Altered submodule"
git push --recurse-submodules=on-demand

snippets Git - 忽略跟踪文件

Git - 忽略跟踪文件

new_gist_file.snippets
git update-index --assume-unchanged .DS_Store

snippets Drupal ADD_JS WITH DATA #ATTACH JS

Drupal ADD_JS WITH DATA #ATTACH JS

normal_add_js.snippets
// normal add_ja

In your MODULENAME.module file use the following code.

$testVariable = 'himanshu';
drupal_add_js(array('MODULENAME' => array('testvar' => $testVariable)), array('type' => 'setting'));
drupal_add_js(drupal_get_path('module', 'MODULENAME') . '/MODULENAME.js');


And in MODULENAME.js use the following one.

(function($) {
  Drupal.behaviors.MODULENAME = {
    attach: function (context, settings) {
      alert(settings.MODULENAME.testvar);
    }
  };

})(jQuery);
attached_add_js.snippets
//In your MODULENAME.module file use the following code. use as per needed

$form['notification_email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email')
);
$form['notification_email']['#attached']['js'][] = array(
  'data' => array('setting_name' => $js_settings),
  'type' => 'setting'
);
$form['notification_email']['#attached']['js'][] = array(
  'data' => 'file.js',
  'type' => 'file'
);
$form['notification_email']['#attached']['js'][] = array(
  'data' => 'http://domain.com/file.js',
  'type' => 'external'
);

///////////////////////////////////////////////

// Method 1, JS or CSS
$element['#attached']['js'][] = $data; // This is assumed to be a local file name. JS or CSS


// Method 2, JS or CSS
$element['#attached']['js'][$data] = $options; // $data can be an external URI, a local file, or inline code.


// Method 3, JS or CSS.  JS settings *must* use this version.
$options['data'] = $data; // $data can be any type
$element['#attached']['js'][] = $options; // Brackets must be empty, or contain a numeric index


// Method 4, libraries are special
$element['#attached']['library'][] = array(
  $module,
  $name,
);




//In your MODULENAME.module file use the following code. use as per needed
//////////////////////////////////////////////////////////////////////////////////////////////

      $form['#attached']['js'][] = array(
        'data' => array('pincode' => $pincode),
        'type' => 'setting',
      );

//In your js file use the following code. use as per needed
//////////////////////////////////////////////////////////////////////////////////////////////

       var pincode = Drupal.settings.pincode;
       console.log('bhavesh');
       console.log(pincode);








snippets 消费WEB-SERVICES json xml

消费WEB-SERVICES json xml

new_gist_file.snippets
CONSUMING WEBSERVICES

JSON SAMPLE API: 
http://ip.jsontest.com/
http://api.geonames.org/weatherJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo

xml sample api:
http://api.geonames.org/cities?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo
http://www.thomas-bayer.com/sqlrest/CUSTOMER

1)Simple way (using file_get_contents)

--------------------------------------------------------------------------
Json:

$response = file_get_contents('http://api.geonames.org/weatherJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo');

//if $response is JSON, use json_decode to turn it into php array:

$response = json_decode($response);

dsm($response);


-------------------------------------------
xml:


$response = file_get_contents('http://www.thomas-bayer.com/sqlrest/CUSTOMER');

//if $response is XML, use simple_xml class:

$xml = simplexml_load_string($response);

$json = json_encode($xml);

$array = json_decode($json,TRUE);

dsm($array);




create custom web services :
http://pingv.com/blog/an-introduction-drupal-7-restful-services

snippets Vhost NGINX CloudPanel

Vhost NGINX CloudPanel

vhost_nginx_cloudpanel.snippets
map $http_user_agent $bad_bot {
  default 0;
   ~(?i)(Ahrefsbot|Baiduspider|YandexBot|Abonti|ShopWiki|FatBot|UnisterBot|Baidu|BLEXBot|Twengabot|httrack|WinHTTrack|htmlparser|urllib|Zeus|scan|email|PyQ|WebCollector|WebCopier|WebCopy|webcraw|LWP::simple|Havij) 1;
}

{{301_redirect}}

server {
    listen 80;
    {{ssl_listener}};
    {{server_name}};
    {{ssl_certificate}};
    {{ssl_certificate_key}};
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128:AES256:AES:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK';
    ssl_prefer_server_ciphers on;
    ssl_stapling on;
    ssl_stapling_verify on;
    client_max_body_size 50m;
    {{root}};

    {{nginx_access_log}};
    {{nginx_error_log}};

    if ($bad_bot = 1) {
      return 403;
    }

    rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
    rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
   
   rewrite ^/dev3$ /dev3/$1 permanent;
   location /dev3/ {
   try_files $uri $uri/ /dev3/index.php?$args;
       index index.php index.html index.htm;
   }
rewrite ^/dev3/mageadmin$ /dev3/mageadmin/$1 permanent;

rewrite ^/dev4$ /dev4/$1 permanent;
location /dev4/ {
	try_files $uri $uri/ /dev4/index.php?$args;
	index index.php index.html index.htm;
}
rewrite ^/dev4/mageadmin$ /dev4/mageadmin/$1 permanent;

rewrite ^/dev5$ /dev5/$1 permanent;
location /dev5/ {
	try_files $uri $uri/ /dev5/index.php?$args;
	index index.php index.html index.htm;
}
rewrite ^/dev5/mageadmin$ /dev5/mageadmin/$1 permanent;

rewrite ^/dev6$ /dev6/$1 permanent;
location /dev6/ {
	try_files $uri $uri/ /dev6/index.php?$args;
	index index.php index.html index.htm;
}
rewrite ^/dev6/mageadmin$ /dev6/mageadmin/$1 permanent;

rewrite ^/dev10$ /dev10/$1 permanent;
location /dev10/ {
	try_files $uri $uri/ /dev10/index.php?$args;
	index index.php index.html index.htm;
}
rewrite ^/dev10/mageadmin$ /dev10/mageadmin/$1 permanent;

rewrite ^/homologacao$ /homologacao/$1 permanent;
location /homologacao/ {
	try_files $uri $uri/ /homologacao/index.php?$args;
	index index.php index.html index.htm;
}
rewrite ^/homologacao/mageadmin$ /homologacao/mageadmin/$1 permanent;

    location /lib/minify/ {
     allow all;
    }

    location ~ (/(app/|includes/|pkginfo/|var/|report/config.xml)|/\.+) {
      deny all;
    }

    #rewrite ^/blog$ /blog/$1 permanent;
    
    #location /blog/ {
    #  try_files $uri $uri/ /blog/index.php?$args;
    #}
    try_files $uri $uri/ /index.php?$args;
    index index.php index.html index.htm;

    location ~ \.php$ {
       include fastcgi_params;
       fastcgi_intercept_errors on;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       try_files $uri =404;
       fastcgi_pass 127.0.0.1:{{php_fastcgi_port}};
       fastcgi_read_timeout 3600;
       fastcgi_send_timeout 3600;
       fastcgi_param HTTPS $fastcgi_https;
       fastcgi_param SERVER_PORT 80;
       fastcgi_param PHP_VALUE "
         error_log={{php_error_log}};
         memory_limit=512M;
         max_execution_time=90;";
       #fastcgi_param MAGE_RUN_CODE "store_code";
       #fastcgi_param MAGE_RUN_TYPE "website";
    }

    gzip                on;
    gzip_disable        "msie6";
    gzip_vary           on;
    gzip_proxied        any;
    gzip_comp_level     8;
    gzip_buffers        16 8k;
    gzip_http_version   1.0;
    gzip_types          text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg;

    location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm|zip|swf)$ {
      add_header Access-Control-Allow-Origin "*";
      expires max;
      access_log off;
    }


    if (-f $request_filename) {
      break;
    }
}

snippets $ .ajax将数据从js发布到php

$ .ajax将数据从js发布到php

js.snippets


(function ($) {
    Drupal.behaviors.shipment_history = {
        attach: function (context, settings) {
            $.noConflict();
            $(".reshipment-button").click(function () {
                var items = new Array();
                $("input[type=checkbox]:checked").each(function () {
                    items.push($(this).attr("id"));
                });
                var base_url = window.location.origin;
                $.ajax({
                    type: "POST",
                    url: base_url + '/reshipment/getdata',
                    cache: false,
                    data: {items: items},
                    success: function (data) {
                        window.location.href = base_url + '/shipment/reshipment'; //simply redirect on click button and get data in session
                    }
                });


            });


        }
    };
})(jQuery);
module.snippets
//create Hook_menu

function icss_shipment_pages_menu() {
  $items = array();
  
  
  //want to post data from this page on click button
    $items['shipment-history-details'] = array(
    'title' => 'shipment history',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('shipment_history_form'),
    'file' => 'includes/shipment_history.inc',
    'file path' => drupal_get_path('module', 'icss_shipment_pages'),
    'access arguments' => array('view shipment history'),
  );
  
  
    $items['reshipment/getdata'] = array(
    'title' => 'Reshipment Get Data',
    'page callback' => 'get_reshipment_data_ajax',
   'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  ); 
    return $items;
}


function get_reshipment_data_ajax() {
  $items = "";
  if (isset($_POST['items'])) {
    $_SESSION['reshipment_data']=$_POST['items'];
  }
   return $data;
  }
  
  

snippets SSH命令

SSH命令

ssh.snippets
cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

OR 

ssh-copy-id user@123.45.56.78

snippets 常用应用程序的键盘快捷键

常用应用程序的键盘快捷键

pycharm.snippets
# Keyboard shortcuts for pycharm editor

# Show a pop-out dialog that allows to search all actions shown with their shortcuts
# ref: http://stackoverflow.com/a/25103854
Ctrl + Shift + A

snippets 常用应用程序的键盘快捷键

常用应用程序的键盘快捷键

pycharm.snippets
# Keyboard shortcuts for pycharm editor

# Show a pop-out dialog that allows to search all actions shown with their shortcuts
# ref: http://stackoverflow.com/a/25103854
Ctrl + Shift + A

snippets 自定义vim python片段

自定义vim python片段

python.snippets
snippet phd       "create python head for the files"
	#!/usr/bin/env python
	# -*- coding: utf-8 -*-

	# -----------------------------------------------------
	#  FileName    :	`expand("%:t")` 
	#  Author      :    wuqingfeng@
	#  Date        :    `strftime("%Y-%m-%d")`
	# -----------------------------------------------------
	${0}