Express & Handlebars Setup

const express = require("express");
const exphbs = require("express-handlebars");
const app = express();

// Handlebars Middleware
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");

// Index Route
const port = 3000;

app.get("/", (req, res) => {
	const title = "Welcome";
    res.render("index", {
       title
    });
});

app.get("/about", (req, res) => {
	res.render("about");
});

app.listen(port, () => console.log(`Listening on port ${port}`));

Shopify - Liquid - Image with Link

An example of how to use liquid to generate a social icon using an image and a link in a single tag.
{{ 'my-twitter-button.png' | asset_url | img_tag | link_to: 'https://twitter.com/iamawesome', 'follow me on twitter' }}

Shopify - Liquid - Image with Link

An example of how to use liquid to generate a social icon using an image and a link in a single tag.
{{ 'my-twitter-button.png' | asset_url | img_tag | link_to: 'https://twitter.com/iamawesome', 'follow me on twitter' }}

deploy

https://project.scmp.tech/product/web/scmp-d8/wikis/deployment/overview

Google Mapのiframe版をレスポンシブに対応させる

<div class="map-wrap">
  <iframe src="https://maps.google.co.jp/maps?output=embed&q=ここに住所が入ります&z=16" width="1000" height="400" frameborder="0" scrolling="no" ></iframe>
  <!--パラメータは適時変更してください  -->
</div>

Example implementation and usage of Semaphores in Golang

package main

import (
	"fmt"
	"math/rand"
)

type empty struct{}
type semaphore chan empty

// acquire n resources
func (s semaphore) Acquire(n int) {
	e := empty{}
	for i := 0; i < n; i++ {
		s <- e
	}
}

// release n resources
func (s semaphore) Release(n int) {
	for i := 0; i < n; i++ {
		<-s
	}
}

/* mutex */
func (s semaphore) Lock()   { s.Acquire(1) }
func (s semaphore) Unlock() { s.Release(1) }

/* signal-wait */
func (s semaphore) Signal()    { s.Release(1) }
func (s semaphore) Wait(n int) { s.Acquire(n) }

func generateRandomNumbers(n int) <-chan float64 {
	ch := make(chan float64)
	sem := make(semaphore, n)

	for i := 0; i < n; i++ {
		sem.Wait(1)
		go func() {
			fmt.Println("put -> |=======|")
			ch <- rand.Float64()
			sem.Signal()
		}()
	}
	// launch extra goroutine to eventually close ch
	go func() {
		fmt.Println("waiting to close")
		sem.Wait(n)
		close(ch)
	}()
	return ch
}

func main() {
	for result := range generateRandomNumbers(10) {
		fmt.Printf("read <- %f |=======|\n", result)
	}
}

Angular checkbox component

import { ReplaySubject } from 'rxjs/index';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { RCUSTATUSES } from 'Helpers/rcustatuses';
import { FormGroup, FormBuilder, FormArray } from '@angular/forms';
import { ModalDirective } from 'ngx-bootstrap/modal/modal.directive';
import { AuthUserService } from 'Services/auth-user.service';
import { finalize, distinctUntilChanged, debounceTime, } from 'rxjs/operators';
import { Component, OnInit, OnChanges, Input, ViewChild, SimpleChanges } from '@angular/core';
import { RelocationChecklistService } from 'AppService/service/relocation-checklist.service';
import { RelocationChecklistStatusService } from 'AppMscCompliance/services/relocation-checklist-status.service';

@Component({
    selector: 'v-relocation-internal-checklist',
    templateUrl: './relocation-internal-checklist.component.html',
    styleUrls: [ './relocation-internal-checklist.component.scss' ],
})
export class RelocationInternalChecklistComponent implements OnInit, OnChanges {

    modalRef: BsModalRef;
    @ViewChild('modal') modal: ModalDirective;

    @Input()
    rcu_case_id: number = null;

    @Input()
    status_name: string = '';

    @Input()
    existing_checklists: any[] = null;

    checklistForm: FormGroup;

    onChanges = new ReplaySubject<SimpleChanges>();

    checklist_items = [
        {
            id: 2,
            name: 'Renting: Stamp certified true copy of tenancy agreement.'
        },
        {
            id: 3,
            name: 'Own premise: Stamp certified true copy of Sales & Purchase Agreement'
        },
        {
            id: 4,
            name: 'Office Space in Sq.Ft'
        },
    ];

    state = {
        can_update: false,
    };

    meta = {
        is_loading: false
    };

    constructor(
        public authUser: AuthUserService,
        private relocationChecklistService: RelocationChecklistService,
        private relocationChecklistStatusService: RelocationChecklistStatusService,
        private fb: FormBuilder
    ) {

    }

    ngOnInit(): void {

        this.checklistForm = this.fb.group({
            checklists: this.buildChecklist()
        });

        // set existing item only when input existing_checklists data is ready

        this.onChanges.subscribe(data => {
            this.setExistingItem(this.existing_checklists);
        });

        // listen for checkbox item changes

        this.itemChanges();

    }

    ngOnChanges(changes: SimpleChanges) {

        if (changes['rcu_case_id'] && this.rcu_case_id) {

            console.log('checklist rcu_case_id', this.rcu_case_id);
        }

        if (changes['status_name'] && this.status_name) {

            // reset the state

            this.state = {
                can_update: false,
            };

            this.enableUpdateChecklist(this.status_name);

        }

        if (changes['existing_checklists'] && this.existing_checklists) {

            console.log('existing_checklists', this.existing_checklists);

            this.onChanges.next(changes);

        }
    }

    // first build of checkbox

    buildChecklist() {

        const controls = this.checklist_items.map(item => this.fb.control(false));

        return this.fb.array(controls);

    }

    // enable update checklist

    private enableUpdateChecklist(status_name: string) {

        if (
            status_name === RCUSTATUSES.IN_PROGRESS
            || status_name === RCUSTATUSES.RESUBMITTED
        ) {
            this.state.can_update = true;
        }

    }

    // getter

    get formData() { return <FormArray> this.checklistForm.get('checklists'); }

    // rebuild checkbox after received pre-checked data from API

    rebuildChecklist(selected_ids: number[]) {

        const controls = [];

        for(let i = 0; i < this.checklist_items.length; i++) {

            let checked = false;

            if (selected_ids.indexOf(this.checklist_items[i].id) !== -1) {
                checked = true;
            }

            const form_state = {
                value: checked,
                disabled: !this.state.can_update
            };

            controls.push(this.fb.control(form_state));
        }

        return this.fb.array(controls);

    }

    // when user check / uncheck item, auto store via API

    itemChanges(): void {

        this.checklistForm.valueChanges
            .pipe(
                debounceTime(400),
                distinctUntilChanged()
            )
            .subscribe(value => {

                const selectedItemIds = this.getSelectedItems();

                console.log(selectedItemIds);

                this.storeChecklist(selectedItemIds);

                this.enableApproveRelocation(selectedItemIds);

            });
    }

    // enable Approve if user checked all the items

    enableApproveRelocation(selectedItemIds) {

        const checklist_item_ids = this.checklist_items.map(function (item) {
            return item.id;
        });

        const item_diff = this.arr_diff(selectedItemIds, checklist_item_ids);

        if (item_diff.length === 0) {
            this.relocationChecklistStatusService.changeStatus(true);
        } else {
            this.relocationChecklistStatusService.changeStatus(false);
        }
    }

    // get latest checked items id

    getSelectedItems() {

        const selectedItemIds = this.checklistForm.value.checklists
            .map((v, i) => v ? this.checklist_items[i].id : null)
            .filter(v => v !== null);

        return selectedItemIds;

    }

    // from API checklists, extract the item id

    getExistingSelectedItemIds(checklist_items) {

        const existing_checklist_item_ids = checklist_items.map(item => item.pivot.checklist_item_id);

        console.log('existing_checklist_item_ids', existing_checklist_item_ids);

        return existing_checklist_item_ids;
    }

    // pre-selected existing checklist

    setExistingItem(existing_checklists) {

        const selected_ids = this.getExistingSelectedItemIds(existing_checklists);

        console.log('selected_ids', selected_ids);

        this.checklistForm.setControl('checklists', this.rebuildChecklist(selected_ids) );

        this.enableApproveRelocation(selected_ids);

    }

    // store latest checklist item

    storeChecklist(items) {

        if (!this.state.can_update) {
            return false;
        }

        this.meta.is_loading = true;

        this.relocationChecklistService.syncItems(this.rcu_case_id, items)
            .pipe(finalize(() => this.meta.is_loading = false ))
            .subscribe(
                res => {
                    console.log(res);
                },
                err => {
                    console.log('err', err);

                });

    }

    arr_diff(a1, a2) {

        const a = [], diff = [];

        for (let i = 0; i < a1.length; i++) {
            a[a1[i]] = true;
        }

        for (let i = 0; i < a2.length; i++) {
            if (a[a2[i]]) {
                delete a[a2[i]];
            } else {
                a[a2[i]] = true;
            }
        }

        for (const k in a) {
            diff.push(k);
        }

        return diff;
    }
}

in

in
in
列表对象初始化为"“

randomise meta description php

for carnextdoor randomise the meta description

      $data['meta_keywords'] = $data['meta_keywords'] . ',' . $data['iserp']['iserp_name'];
      if(isset($data['first_result_description']) && !empty($data['first_result_description']))
      {
        $data['meta_description'] = stripslashes($data['iserp']['iserp_name']) . ',' . $data['first_result_description'];
      }

      if(in_array($data['iserp']['category_name'] , ['nsw' ,'vic'])) {
        $meta_description_variations = [
          //Variation 1
          'Insurance covered. Low prices Neighbour car hire, save Borrow neighbours\' ute from $35/day+33c/km. Utes all over ' . 
           $data['iserp']['category_name'] .
           ' rent by hour Borrow utes today, good range in '.
           $data['iserp']['category_name']
           .', insurance covered, keys at car',
          //Variation 2
          'Insurance covered, Low prices Keys are Car, Drive Now Borrow neighbours\' ute from $35/day+33c/km, utes all over '. 
          $data['iserp']['category_name'] . 
          ' rent by hour Borrow ute hourly from $7/hr+33c/km, utes all over '.
          $data['iserp']['category_name']
          .' hire now'
        ];
        shuffle($meta_description_variations);
        $data['meta_description'] = array_pop($meta_description_variations);
      }

Helpers de SASS

$mobile-width: 390px;
$tablet-width: 980px;
$desktop-width: 1280px;

$smartphone-width: 576px;
$sm-desktop-width: 992px;

$breakpoints: (small:$mobile-width,
medium:$tablet-width,
large:$desktop-width);

@each $key,$val in $breakpoints {
    $name: $key;
    // Remove the units. Not strictly necessary, but it
    // makes the class names less unweildy
    // @see http://stackoverflow.com/a/12335841/362769
    // EXAMPLE - Mostrar a 1 imagem a partir do mobile pra cima e mostrar a outra ate o mobile
    //  <img src="./img/_featured3.png" alt=" Anna &lt;br&gt; Laura" class="show-min-small">
    // <img src="./img/_featured3--mobile.png"alt=" Anna &lt;br&gt; Laura"class="show-max-small">
    
    $num: $val / ($val * 0 + 1);

    @media(min-width: $val) {
        .hide-min-#{$name} {
            display: none!important;
        }
        .show-min-#{$name} {
            display: block !important;
        }
    }

    @media(max-width: $val - 1) {
        .show-max-#{$name} {
            display: block!important;
        }
        .hide-max-#{$name} {
            display: none !important;
        }
    }
}


.no__horizontal--padding {
    padding-left: 0px;
    padding-right: 0px;
}

.no__horizontal--padding-right {
    padding-right: 0px;
}

.no__horizontal--padding-left {
    padding-left: 0px;
}

.transicao {
    transition: all 0.5s;
}

.show {
    opacity: 1;
    height: auto;
    visibility: visible;
}

.hide {
    opacity: 0;
    height: 0;
    visibility: hidden;
    min-height: 0px !important;
}

ES6 Syntax

New items in the ES6 Syntax
'use strict';

Vuex Map Helpers

Vuex Map Helpers
// Option 1
import { mapState } from 'vuex'

export default {
  // ...
  computed: mapState({
    // arrow functions can make the code very succinct!
    count: state => state.count,

    // passing the string value 'count' is same as `state => state.count`
    countAlias: 'count',

    // to access local state with `this`, a normal function must be used
    countPlusLocalState (state) {
      return state.count + this.localCount
    }
  })
}

// Option 2
computed: mapState([
  // map this.count to store.state.count
  'count'
])

// Option 3
computed: {
  localComputed () { /* ... */ },
  // mix this into the outer object with the object spread operator
  ...mapState({
    // ...
  })
}

provisioningTeamProfile

 PRODUCT_BUNDLE_IDENTIFIER = $(PRODUCT_BUNDLE_IDENTIFIER)
 PROVISIONING_PROFILE = 6001a2b7-7a1d-4167-9620-0593bdb9cbeb
 PROVISIONING_PROFILE_SPECIFIER = EventbaseiOSDevTeam

Problems with Pending Charges

Pending charges process can fail for many reasons. Some are that the CPT4 is invalid, some are its an expired SIM, some are a 0 quantity etc. Try the below scripts to search for these sitautions.
select * from service_item_mstr where cpt4_code_id not in (select cpt4_code_id from cpt4_code_mstr)
--does any of the sims have missing cpt4 codes?

select * from pending_charge pc
left join patient_procedure pp on pc.uniq_id = pp.uniq_id
left join service_item_mstr sim on sim.service_item_lib_id = pp.service_item_lib_id and sim.service_item_id = pp.service_item_id and sim.exp_date = (select top 1 exp_date from service_item_mstr sim2 where sim.service_item_lib_id = sim2.service_item_lib_id and sim.service_item_id = sim2.service_item_id order by exp_date desc)
where sim.exp_date < getdate()

--do any of the pending charges have expired sims?

select * from pending_charge pc
left join patient_procedure pp on pc.uniq_id = pp.uniq_id
where pp.qty <1 or pp.qty = '' or pp.qty is null

Remove diacritics - strtr

<?php

    private function removeDiacritics($str)
    {
        return strtr($str, "ÁÄČÇĎÉĚËÍŇÓÖŘŠŤÚŮÜÝŽáäčçďéěëíňóöřšťúůüýž", "AACCDEEEINOORSTUUUYZaaccdeeeinoorstuuuyz");
    }

Vuex Chat App

An example of a Vuex Chat App
const data = require('./mock-data')
const LATENCY = 16

export function getAllMessages (cb) {
  setTimeout(() => {
    cb(data)
  }, LATENCY)
}

export function createMessage ({ text, thread }, cb) {
  const timestamp = Date.now()
  const id = 'm_' + timestamp
  const message = {
    id,
    text,
    timestamp,
    threadID: thread.id,
    threadName: thread.name,
    authorName: 'Evan'
  }
  setTimeout(function () {
    cb(message)
  }, LATENCY)
}