var, let, const 차이점은?

  • var function-scoped이고, let, const block-scoped입니다.

  • function-scoped block-scoped가 무슨말이냐?

var(function-scoped)

jsfiddle 참고주소

// var는 function-scope이기 때문에 for문이 끝난다음에 i를 호출하면 값이 출력이 잘 된다.
// 이건 var가 hoisting이 되었기 때문이다.
for(var j=0; j<10; j++) {
  console.log('j', j)
}
console.log('after loop j is ', j) // after loop j is 10


// 아래의 경우에는 에러가 발생한다.
function counter () {
  for(var i=0; i<10; i++) {
    console.log('i', i)
  }
}
counter()
console.log('after loop i is', i) // ReferenceError: i is not defined

그럼 항상 function을 만들어서 호출해야 할까? 그건 아니다.

javascript에서는 immediately-invoked function expression (or IIFE, pronounced "iffy")라는것이 있다.

IIFE function-scope인거 처럼 만들 수가 있다.

// IIFE를 사용하면
// i is not defined가 뜬다.
(function() {
  // var 변수는 여기까지 hoisting이 된다.
  for(var i=0; i<10; i++) {
    console.log('i', i)
  }
})()
console.log('after loop i is', i) // ReferenceError: i is not defined

근데 javascript는 여기서 좀 웃긴 부분이 있다.

위에서 잠깐 말했지만 IIFE function-scope처럼 보이게 만들어주지만 결과가 같지는 않다.

// 이 코드를 실행하면 에러없이 after loop i is 10이 호출된다.
(function() {
  for(i=0; i<10; i++) {
    console.log('i', i)
  }
})()
console.log('after loop i is', i) // after loop i is 10

위에 코드가 아무 에러 없이 실행되는 이유는 i가 hoisting이 되어서 global variable이 되었기 때문이다.

그래서 아래와 같이 된 것이다.

var i
(function() {
  for(i=0; i<10; i++) {
    console.log('i', i)
  }
})()
console.log('after loop i is', i) // after loop i is 10

IIFE는 쓰는데 이렇게 hoisting이 된다면 무슨 소용이 있겠는가?!

그래서 이런 hoisting을 막기 위해 use strict를 사용한다.

// 아까랑 다르게 실행하면 i is not defined라는 에러가 발생한다.
(function() {
  'use strict'
  for(i=0; i<10; i++) {
    console.log('i', i)
  }
})()
console.log('after loop i is', i) // ReferenceError: i is not defined

어떤가? 뭔가 변수 선언때문에 너무 많은 일을 한다고 생각하지 않는가?

그럼 let, const에 대해서 알아보자.

let, const(block-scoped)

  • es2015에서는 let, const가 추가 되었다.

javascipt에는 그동안 var만 존재했기 때문에 아래와 같은 문제가 있었다.

// 이미 만들어진 변수이름으로 재선언했는데 아무런 문제가 발생하지 않는다.
var a = 'test'
var a = 'test2'

// hoisting으로 인해 ReferenceError에러가 안난다.
c = 'test'
var c

위와 같은 문제점으로 인해 javascript를 욕 하는 사람이 참 많았다.

하지만 let, const를 사용하면 var를 사용할때보다 상당히 이점이 많다.

두개의 공통점은 var와 다르게 변수 재선언 불가능이다.

let const의 차이점은 변수의 immutable여부이다.

let은 변수에 재할당이 가능하지만,

const는 변수 재선언, 재할당 모두 불가능하다.

// let
let a = 'test'
let a = 'test2' // Uncaught SyntaxError: Identifier 'a' has already been declared
a = 'test3'     // 가능

// const
const b = 'test'
const b = 'test2' // Uncaught SyntaxError: Identifier 'a' has already been declared
b = 'test3'    // Uncaught TypeError:Assignment to constant variable.

let, const가 hoisting이 발생하지 않는건 아니다.

var function-scoped로 hoisting이 되었다면

let, const block-scoped단위로 hoisting이 일어나는데

c = 'test' // ReferenceError: c is not defined
let c

위에 코드에서 ReferenceError가 발생한 이유는 tdz(temporal dead zone)때문이다.

let은 값을 할당하기전에 변수가 선언 되어있어야 하는데 그렇지 않기 때문에 에러가 난다.

이건 const도 마찬가지인데 좀 더 엄격하다.

// let은 선언하고 나중에 값을 할당이 가능하지만
let dd
dd = 'test'

// const 선언과 동시에 값을 할당 해야한다.
const aa // Missing initializer in const declaration

이렇게 javascript에 tdz가 필요한 이유는 동적언어이다 보니깐 runtime type check 가 필요해서이다.

Reference












Reference: https://gist.github.com/LeoHeo/7c2a2a6dbcf80becaaa1e61e90091e5d







우분투를 안쓴지 제법되었는데.. 솔직히 CensOS를 신봉하는 나로서는..

새로운 것을 지원 빨리한다. Ubuntu.. 안정적인 것을 원한다. CentOS.. 이런 형식으로 약간..

이건 뭐 제 느낌이라.


BlockChain을 개발하는 나에게 이상하게 자료를 찾다보면 Ubuntu 와 연관이 많아 다시 한번 써보려 한다.

사실 아직도 크게 신뢰 하진 않으나.. 12.04가 벌써 18.04가 되어 있었다.


각설..

Introduction

VNC, or "Virtual Network Computing", is a connection system that allows you to use your keyboard and mouse to interact with a graphical desktop environment on a remote server. It makes managing files, software, and settings on a remote server easier for users who are not yet comfortable with the command line.

In this guide, we will be setting up VNC on an Ubuntu 18.04 server and connecting to it securely through an SSH tunnel. The VNC server we will be using is TightVNC, a fast and lightweight remote control package. This choice will ensure that our VNC connection will be smooth and stable even on slower internet connections.

Prerequisites

To complete this tutorial, you'll need:

  • An Ubuntu 18.04 Droplet set up via the Ubuntu 18.04 initial server setup tutorial, which includes having a sudo non-root user. Note that this tutorial can be completed using any size Droplet, but a VNC built on a smaller droplet may have more limits on functionality than a larger one.

  • A local computer with a VNC client installed that supports VNC connections over SSH tunnels. If you are using Windows, you could use TightVNC, RealVNC, or UltraVNC. Mac OS X users can use the built-in Screen Sharing program, or can use a cross-platform app like RealVNC. Linux users can choose from many options: vinagrekrdc, RealVNC, TightVNC, and more.

Step 1 — Installing the Desktop Environment and VNC Server

By default, an Ubuntu 18.04 Droplet does not come with a graphical desktop environment or a VNC server installed, so we'll begin by installing those. Specifically, we will install packages for the latest Xfce desktop environment and the TightVNC package available in the official Ubuntu repository.

On your server, install the Xfce and TightVNC packages.

  • sudo apt-get update
  • sudo apt install xfce4 xfce4-goodies tightvncserver

To complete the VNC server's initial configuration after installation, use the vncserver command to set up a secure password.

  • vncserver

You'll be prompted to enter and verify a password, and also a view-only password. Users who log in with the view-only password will not be able to control the VNC instance with their mouse or keyboard. This is a helpful option if you want to demonstrate something to other people using your VNC server, but isn't necessary.

Running vncserver completes the installation of VNC by creating default configuration files and connection information for our server to use. With these packages installed, you are now ready to configure your VNC server.

Step 2 — Configuring the VNC Server

First, we need to tell our VNC server what commands to perform when it starts up. These commands are located in a configuration file called xstartup in the .vnc folder under your home directory. The startup script was created when you ran the vncserver in the previous step, but we need modify some of the commands for the Xfce desktop.

When VNC is first set up, it launches a default server instance on port 5901. This port is called a display port, and is referred to by VNC as :1. VNC can launch multiple instances on other display ports, like :2:3, etc. When working with VNC servers, remember that :X is a display port that refers to 5900+X.

Because we are going to be changing how the VNC server is configured, we'll need to first stop the VNC server instance that is running on port 5901.

  • vncserver -kill :1

The output should look like this, with a different PID:

Output
Killing Xtightvnc process ID 17648

Before we begin configuring the new xstartup file, let's back up the original.

  • mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

Now create a new xstartup file with nano or your favorite text editor.

  • nano ~/.vnc/xstartup

Paste these commands into the file so that they are performed automatically whenever you start or restart the VNC server, then save and close the file.

~/.vnc/xstartup
#!/bin/bash xrdb $HOME/.Xresources startxfce4 &

The first command in the file, xrdb $HOME/.Xresources, tells VNC's GUI framework to read the server user's .Xresources file. .Xresources is where a user can make changes to certain settings of the graphical desktop, like terminal colors, cursor themes, and font rendering. The second command simply tells the server to launch Xfce, which is where you will find all of the graphical software that you need to comfortably manage your server.

To ensure that the VNC server will be able to use this new startup file properly, we'll need to grant executable privileges to it.

  • sudo chmod +x ~/.vnc/xstartup

Now, restart the VNC server.

  • vncserver

The server should be started with an output similar to this:

Output
New 'X' desktop is your_server_name.com:1 Starting applications specified in /home/sammy/.vnc/xstartup Log file is /home/sammy/.vnc/liniverse.com:1.log

Step 3 — Testing the VNC Desktop

In this step, we'll test the connectivity of your VNC server.

First, we need to create an SSH connection on your local computer that securely forwards to the localhost connection for VNC. You can do this via the terminal on Linux or OS X with following command. Remember to replace user and server_ip_address with the sudo non-root username and IP address of your server.

  • ssh -L 5901:127.0.0.1:5901 -N -f -l username server_ip_address

If you are using a graphical SSH client, like PuTTY, use server_ip_address as the connection IP, and set localhost:5901 as a new forwarded port in the program's SSH tunnel settings.

Next, you may now use a VNC client to attempt a connection to the VNC server at localhost:5901. You'll be prompted to authenticate. The correct password to use is the one you set in Step 1.

Once you are connected, you should see the default Xfce desktop. It should look something like this:

VNC connection to Ubuntu 16.04 server

You can access files in your home directory with the file manager or from the command line, as seen here:

Files via VNC connection to Ubuntu 16.04

Step 4 — Creating a VNC Service File

Next, we'll set up the VNC server as a systemd service. This will make it possible to start, stop, and restart it as needed, like any other systemd service.

First, create a new unit file called /etc/systemd/system/vncserver@.service using your favorite text editor:

  • sudo nano /etc/systemd/system/vncserver@.service

Copy and paste the following into it. Be sure to change the value of User and the username in the value of PIDFILE to match your username.

/etc/systemd/system/vncserver@.service
[Unit] Description=Start TightVNC server at startup After=syslog.target network.target [Service] Type=forking User=sammy PAMName=login PIDFile=/home/sammy/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target

Save and close the file.

Next, make the system aware of the new unit file.

  • sudo systemctl daemon-reload

Enable the unit file.

  • sudo systemctl enable vncserver@1.service

The 1 following the @ sign signifies which display number the service should appear over, in this case the default :1 as was discussed above. 
Stop the current instance of the VNC server if it's still running.

  • vncserver -kill :1

Then start it as you would start any other systemd service.

  • sudo systemctl start vncserver@1

You can verify that it started with this command:

  • sudo systemctl status vncserver@1

If it started correctly, the output should look like this:

Output
vncserver@1.service - TightVNC server on Ubuntu 18.04
   Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2016-04-25 03:21:34 EDT; 6s ago
  Process: 2924 ExecStop=/usr/bin/vncserver -kill :%i (code=exited, status=0/SUCCESS)

...

 systemd[1]: Starting TightVNC server on Ubuntu 18.04...
 systemd[2938]: pam_unix(login:session): session opened for user finid by (uid=0)
 systemd[2949]: pam_unix(login:session): session opened for user finid by (uid=0)
 systemd[1]: Started TightVNC server on Ubuntu 18.04.

Conclusion

You should now have a secured VNC server up and running on your Ubuntu 18.04 server. Now you'll be able to manage your files, software, and settings with an easy-to-use and familiar graphical interface.







Reference: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-16-04





 

For some reason Apple do not make this a straightforward process. After I’ve created a new signature for my client I often spend a while on Skype guiding them through the process of getting it into Apple Mail. So, here’s a short guide. This guide is intended for people that do not use iCloud Storage.

1. The HTML

If you’re not sure about how to create a snazzy email signature then hire somebody to create it for you. They will know the limitations for creating a signature that looks great on all platforms. Ask them to provide you with the HTML with opening <body> and closing </body> tags as a .txt file (if they provide it as a .html file, then simply change the .html to .txt).

2. Create a signature in Apple Mail

You need to do this so that your Mac creates a file, where you’ll then paste the HTML. Go to Apple Mail > Preferences… > Signatures and click the + button at the bottom of the second column (your signatures list).

Give your new signature a title and leave it at that (you don’t need to enter any text in the third (content) column, as you’ll be replacing this content later). Drag the signature (from the second column) on top of the email account you would like it to be associated with.

Quit Mail.

3. Open the Signatures folder

The quickest way of doing this is go to go your Finder and in the top menu bar click Go > Go to Folder… and enter “~/Library/Mail/” (excluding the quote marks). Now, you might see a few folders here. Select the latest “V” folder. For example if you see V2, V3 and V4 folders, open V4 (High Sierra is now V5, so open that one). Now open MailData > Signatures.

4. Paste the HTML Signature

In the Signatures folder (if you’ve got a lot of files in this folder, view the folder as a list and order by the Date Modified column) locate the newest file that ends .mailsignature and will have a load of letters and numbers as the file name. Right-Click or CTRL-Click on the signature and choose Open With > TextEdit.

Delete all text starting from <body

Open your new HTML Signature file (that your designer/developer provided) in TextEdit and copy the text (only copy from the start of, and including, <body> tag and ending at, and including the </body> tag and paste into position in the previous file you’ve just opened

Save, but do not close, the file.

5. Lock the file

Go back to your Finder, highlight the .mailsignature file and select File > Get Info and check the “Locked” checkbox.

6. Look at your lovely new signature!

Open Apple Mail and create a new email (File > New Message). Select your new email signature from the Signatures dropdown and there you have it!

Anything else…

Default Signature. If you would like this to be your default signature go to File > Preferences… > Signatures. Select your email account in the first column from the Choose Signature dropdown, select your new signature.




Tip. 5. lock하는 부분 잊지 마시고, 재 실행 하는 것도 잊지마세요.








reference: https://www.daretothink.co.uk/html-email-signature-in-apple-mail/







'Informatioin > Apple' 카테고리의 다른 글

HTML email signature in Apple Mail  (0) 2018.05.04

어느덧..

나는 Senior Software Engineer라는 타이틀을 얻게되었다.

Developer와 Engineer의 차이가 모호한 상태에서 Engineer란 무엇이고,

이 사람들은 나에게 어떠한 능력을 요구하는가에 대한 궁금증이 생겼다.


What's The Difference Between a Developer and an Engineer?

수많은 글에서 알 수 있듯이 이 차이를 명확하게 아는 사람은 별로없다.


Developer 가 개발에 좀 더 치중 하였다면, Engineer 는 이를 포괄하여 더 많은 것들을 할 수 있는 이러한 뉘앙스를 보여준다.

대충 이러한 내용으로 내 머리에 저장하고, 다시 Engineer 가 뭘까 고민해 보았다.

사실.. 이런 것을 고민 할 나이는 아닌 것 같고, 고민 할 시간도 없는데,

문득 내가 뭘해야 하는가에 대한 의문에서 부터 그 궁금증은 더해갔다.


어떤 사람이 써놓은 글귀가 나를 그 궁금증에서 조금이나마 해소되게 해주었다.


공학에 대해 정의:

'' 한문으로 하면, '' 입니다. 여기서 위의 '' 과학이고, 아래의 '' 현실입니다. 그럼 공학이란 위의 '' 아래의 '' 이어주는 '|' 것을 뜻 함.

, 과학과 현실을 이어주는 학문이 공학이라고 정의.


그래 나는 꿈을 현실로 만들어 주는 사람이다.


로샤스





    /**
* @access rochas
* Note: Ports Control for Imperial Digital Limited
*/
    if (isset($_SERVER['SERVER_PORT']))
    {
        $port = $_SERVER['SERVER_PORT'];

        function route_r($path_r)
        {
            if (isset($_SERVER['PATH_INFO'])) $_SERVER['PATH_INFO'] = str_replace('api', $path_r, $_SERVER['PATH_INFO']);
            if (isset($_SERVER['QUERY_STRING'])) $_SERVER['QUERY_STRING'] = str_replace('api', $path_r, $_SERVER['QUERY_STRING']);
            if (isset($_SERVER['ORIG_PATH_INFO'])) $_SERVER['ORIG_PATH_INFO'] = str_replace('api', $path_r, $_SERVER['ORIG_PATH_INFO']);
            if (isset($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI'] = str_replace('api', $path_r, $_SERVER['REQUEST_URI']);
        }
        
        if ($port == 3031) route_r('customer/api');
        if ($port == 3032) route_r('manager/api');
        if ($port == 3033) route_r('other/api');
        if ($port == 3034) route_r('food/api');
    }





아끕다.. https 때문에 다 소용없게 되어버림..


그래도, 자알~~ 배웠습니다.






+ Recent posts