Skip to content

Instantly share code, notes, and snippets.

View nanlabsweb's full-sized avatar

nanlabsweb

View GitHub Profile
@nanlabsweb
nanlabsweb / post-upstart.sh
Created August 18, 2016 11:40
POST - Upstart script example for nodejs.
description "Example App"
author "Nobody"
start on filesystem or runlevel [2345]
stop on shutdown
# Automatically Respawn:
respawn
respawn limit 99 5
@nanlabsweb
nanlabsweb / post-get-source-builder.groovy
Created August 18, 2016 11:51
POST - Retrieve search source builder.
SearchSourceBuilder getSearchSourceBuilder(QueryWrapper queryWrapper) {
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()
if (queryWrapper.query) {
sourceBuilder.query(queryWrapper.query)
}
if (queryWrapper.fields) {
sourceBuilder.fields(queryWrapper.fields)
}
@nanlabsweb
nanlabsweb / post-search-query.groovy
Created August 18, 2016 11:52
POST - Execute search query.
IndexResponse search(ParamsWrapper queryWrapper) {
elasticSearchHelper.withElasticSearch { Client client ->
SearchSourceBuilder sourceBuilder = getSearchSourceBuilder(queryWrapper)
SearchRequest request = new SearchRequest()
request.searchType(SearchType.DFS_QUERY_THEN_FETCH).indices(queryWrapper.indices).types(queryWrapper.types).source(sourceBuilder)
log.debug "Query:$sourceBuilder"
SearchResponse response = client.search(request).actionGet()
return new IndexResponse(response)
@nanlabsweb
nanlabsweb / post-index-classes.groovy
Created August 18, 2016 11:53
POST - Index metadata.
void indexAll() {
elasticSearchHelper.withElasticSearch { Client client ->
MyDomainClass.list().each { MyDomainClass instance ->
client.index {
index "myIndex"
type "myDomainClass"
id instance.id
source instance
}
}
@nanlabsweb
nanlabsweb / post-contact-controller.js
Created August 18, 2016 11:56
POST - Angular controller example.
function ContactCtrl($scope, ContactService) {
$scope.firstName = '';
$scope.lastName = '';
$scope.getFullName = function() {
if ($scope.firstName !== '' && $scope.lastName !== '') {
return $scope.firstName + ', ' + $scope.lastName;
} else if ($scope.firstName !== '') {
return $scope.firstName;
@nanlabsweb
nanlabsweb / post-contact-form.html
Created August 18, 2016 11:58
POST - Angular view form example.
<form ng-controller="ContactCtrl">
<label>Name</label>
<input type="text" ng-model="contact.name" />
<label>Enabled</label>
<input type="checkbox" ng-model="contact.isEnabled()" />
<div ng-show="contact.isFavorite()">
<p>More data just for favorite contacts...</p>
@nanlabsweb
nanlabsweb / post-contact.js
Created August 18, 2016 11:59
POST - JS plain object example.
/**
* contact.js
**/
var Contact = function () {
// Constructor, sets the defaults values of the object
var clazz = function (attributes) {
var defaults = {
id: null,
@nanlabsweb
nanlabsweb / post-form-controller.js
Created August 18, 2016 12:04
POST - Form controller which uses a model to create/edit instances of it.
app.controller('formCtl', function($scope, $location, $routeParams, contactService) {
var contactId = ($routeParams.id) ? parseInt($routeParams.id, 10) : null;
$scope.contact = (contactId) ? contactService.get(contactId) : new Contact();
$scope.title = ($scope.contact.isNew()) ? 'Add New Contact' : 'Edit Contact';
$scope.types = CONTACT_TYPES;
$scope.saveAction = function() {
if ($scope.contactForm.$valid) {
contactService.save($scope.contact);
@nanlabsweb
nanlabsweb / create_wordpress_mysql.sh
Last active December 6, 2016 13:42
POST - Create MySQL container
#!/bin/bash
BASE_PATH=`pwd`
MYSQL_ROOT_PASSWORD=root
echo "=== Creating 'wordpress_mysql' with (mysql:5.7) ==="
echo "=== Variables ==="
echo '$MYSQL_ROOT_PASSWORD=' XXXXXXXXXX
@nanlabsweb
nanlabsweb / create_wordpress.sh
Created December 6, 2016 13:41
POST - Create WordPress container
#!/bin/bash
BASE_PATH=`pwd`
WORDPRESS_DB_USER=root
WORDPRESS_DB_PASSWORD=root
WORDPRESS_DB_NAME=wordpress
APACHE_CONFIGURATION=$BASE_PATH/wordpress/000-default.conf
echo "=== Creating 'wordpress' with (wordpress) ==="
echo "=== Variables ==="