Sing's Log

Knowledge worth sharing


  • Home

  • Tags

  • Timeline

  • Portfolio

  • Service

  • Search

Find ports status on Windows

Posted on 2018-05-03 | Edited on 2024-07-16 |

To find ports status on windows, there is a default Windows GUI - Resource Monitor or you could use netstat via command prompt.

Read more »

Transact-SQL cheat sheet

Posted on 2018-04-25 | Edited on 2024-07-16 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- Get current datetime
GETDATE()

-- Get year of datetime
YEAR(GETDATE())

-- Get difference between dates
DATEDIFF(dateformat, startdate, enddate)

-- Subtract date, e.g.: DATEADD(HOUR, -11, GETDATE())
DATEADD(Unit of time, value, date)

-- Avalable Unit of time value
NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, WEEKDAY, WEEK, DAY, DAYOFYEAR, MONTH, QUARTER, YEAR

-- Between
select * from User where CreatedDate between '2016-09-26' and '2016-09-27'

-- Order by
select * from User order by column desc

-- Group by
select UserCode, Count(*) from User group by UserCode

-- Select top 10
SELECT TOP (10) * from User

Linux Remote Desktop Viewer to Windows error connecting to host

Posted on 2018-04-14 | Edited on 2024-07-16 |

Today When I connect to Windows through Remote Desktop Viewer got error connecting to host prompt.
After searching the solution is to remove the server I’m having issue in $home/.freerdp/known_hosts and reconnecting again.

1
2
[sing@study ~]$ vi ~/.freerdp/known_hosts
# In Vim, remove the line start with server ip you are connecting to by `dd`, and `:wq` to save the file.

Reference: https://superuser.com/questions/834447/vinagre-remote-desktop-viewer-for-gnome-isnt-working-out-of-box

HttpClient PostAsync/GetAsync JSON Example

Posted on 2018-04-11 | Edited on 2024-07-16 |

PostAsync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
static readonly HttpClient Client = new HttpClient();
public async Task<T> PostAsync<T>(string url, object data) where T : class, new()
{
try
{
string content = JsonConvert.SerializeObject(data);
var buffer = Encoding.UTF8.GetBytes(content);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await Client.PostAsync(url, byteContent).ConfigureAwait(false);
string result = await response.Content.ReadAsStringAsync();
if (response.StatusCode != HttpStatusCode.OK)
{
logger.Error($"GetAsync End, url:{url}, HttpStatusCode:{response.StatusCode}, result:{result}");
return new T();
}
logger.Info($"GetAsync End, url:{url}, result:{result}");
return JsonConvert.DeserializeObject<T>(result);
}
catch (WebException ex)
{
if (ex.Response != null)
{
string responseContent = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
throw new System.Exception($"response :{responseContent}", ex);
}
throw;
}
}

GetAsync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
static readonly HttpClient Client = new HttpClient();
public async Task<string> GetAsync(string url, object data)
{
try
{
string requestUrl = $"{url}?{GetQueryString(data)}";
logger.Info($"GetAsync Start, requestUrl:{requestUrl}");
var response = await Client.GetAsync(requestUrl).ConfigureAwait(false);
string result = await response.Content.ReadAsStringAsync();
logger.Info($"GetAsync End, requestUrl:{requestUrl}, HttpStatusCode:{response.StatusCode}, result:{result}");
return result;
}
catch (WebException ex)
{
if (ex.Response != null)
{
string responseContent = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
throw new Exception($"Response :{responseContent}", ex);
}
throw;
}
}

private static string GetQueryString(object obj)
{
var properties = from p in obj.GetType().GetProperties()
where p.GetValue(obj, null) != null
select p.Name + "=" + HttpUtility.UrlEncode(p.GetValue(obj, null).ToString());

return String.Join("&", properties.ToArray());
}

Abbreviation in Software Engineering

Posted on 2018-04-10 | Edited on 2024-07-16 |

This sheet is to record abbreviation in my daily work as a software engineer.

Abbreviation Full name Explain
CDC Change data capture Use to sync one db data change to another db
MPLS Multi-Protocol Label Switching Link site to site network like both in same network
IDC Internet Data Center Buildings where we put servers
REST REpresentational State Transfer Architectural style defines a set of constraints on HTTP
CNAME Canonical Name A DNS record to point a/b/c domain to d domain so you don’t have to add A record in a/b/c
ACL Access Control List An ACL specifies which users or system processes are granted access to objects

Jenkins migration

Posted on 2018-04-10 | Edited on 2024-07-16 |
  1. Copy existing jenkins folder, exclude workspace
  2. Modify jenkins port in Jenkins.xml, default 8080
  3. Modify AD Domain and rename an account to yours in config.xml
  4. Create / Start Jenkins service in cmd with administrator mode:

    1
    2
    sc create <jenkins-service-name> <path/to/jenkins.exe>
    sc start <jenkins-service-name>
  5. View migrated jenkins in your browser with port specify above, default http://localhost:8080

How Redux work ?

Posted on 2018-04-02 | Edited on 2024-07-16 |

If you want to understand how Redux work, createStore(reducer) is the core function you should know and try to implement yourself. Here is a basic example of Redux, don’t worry I will break it down later :

Read more »

ReactJS performance tuning tips

Posted on 2018-04-02 | Edited on 2024-07-16 |
  1. Use React.PureComponent, it implement shouldComponentUpdate() by shallow compare prop and state, it is powerful with Immutable.js.
  2. Use Chrome extension and checked highlight updates in dev tool to find any unnecessary updates.
  3. Use React-virtualized for render huge list in small chunk at a time.
  4. Use Production build, for example with webpack you need following config:

    1
    2
    3
    4
    new webpack.DefinePlugin({
    'process.env.NODE_ENV': JSON.stringify('production')
    }),
    new webpack.optimize.UglifyJsPlugin()

Install ELK on linux

Posted on 2018-03-30 | Edited on 2024-07-16 |

Before Start

Make sure the server has internet access or you will have to download and upload packages manually. If the server doesn’t, I recommend CCProxy to grant temporary internet access.

Install JDK

1
2
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.rpm
rpm -ivh jdk-8u161-linux-x64.rpm

Elasticsearch

  1. Download and install

    1
    2
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.rpm
    rpm -ivh elasticsearch-6.2.3.rpm
  2. Start service

    1
    2
    3
    4
    5
    6
    7
    # Auto start elasticsearch when computer start
    systemctl daemon-reload
    systemctl enable elasticsearch.service

    # start service
    systemctl start elasticsearch
    systemctl status elasticsearch
  3. Verify Elastic search is running

    1
    2
    3
    4
    curl http://localhost:9200

    # If not working, you could try reboot
    reboot -r

    You could check log files under /var/log/elasticsearch/

  4. Reference : https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html

Kibana

  1. Download and install

    1
    2
    wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.3-x86_64.rpm
    rpm -ivh kibana-6.2.3-x86_64.rpm
  2. Modify kibana config

    1
    2
    3
    4
    5
    vi /etc/kibana/kibana.yml
    # Kibana port
    server.port: 5601
    # Bind to all ip address
    server.host: "0.0.0.0"
  3. Start service

    1
    2
    3
    4
    systemctl daemon-reload
    systemctl enable kibana.service
    systemctl start kibana
    systemctl status kibana
  4. Verify installation

    1
    curl localhost:5601

    You can check log file under /var/log/kibana/

  5. Reference : https://www.elastic.co/guide/en/kibana/current/rpm.html

Logstash

  1. Download and install

    1
    2
    wget https://artifacts.elastic.co/downloads/logstash/logstash-6.2.3.rpm
    rpm -ivh logstash-6.2.3.rpm
  2. Modify logstash.yml to enable auto reload config

    1
    2
    3
    vi /etc/logstash/logstash.yml
    config.reload.automatic: true
    config.reload.interval: 3s
  3. Add first logstash config

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    cd /etc/logstash/conf.d/
    cat > default.conf
    input {
    beats {
    port => 5044
    }
    }
    output {
    elasticsearch {
    hosts => ["http://localhost:9200"]
    }
    }
  4. Start service

    1
    2
    3
    4
    systemctl daemon-reload
    systemctl enable logstash.service
    systemctl start logstash
    systemctl status logstash
  5. Verify installation

    1
    telnet 127.0.0.1 5044

    You could check log file under /var/log/logstash/

  6. Reference : https://www.elastic.co/guide/en/logstash/current/installing-logstash.html

Grant server internet access by ccproxy in linux

Posted on 2018-03-30 | Edited on 2024-07-16 |

It is painful to install something on server without internet access, you need to download package manually and upload it. CCProxy could help your server use your computer internet temporarily, here is the steps :

  1. Download CCProxy
  2. Go through CCProxy setup wizard
  3. Open CCProxy > Options to check your port and your ip address.
  4. Login to your linux server, use your CCProxy as proxy server, then you can curl to check if it works.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [root@linux ~]# export http_proxy=http://172.16.49.170:808/
    [root@linux ~]# export https_proxy=http://172.16.49.170:808/
    [root@linux ~]# curl http://www.google.com
    <!DOCTYPE html>
    <html lang=en>
    <meta charset=utf-8>
    <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
    <title>Error 404 (Not Found)!!1</title>
    <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
    </style>
    <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
    <p><b>404.</b> <ins>That’s an error.</ins>
    <p>The requested URL <code>/1.1</code> was not found on this server. <ins>That’s all we know.</ins>
1…456…9
Sing Ming Chen

Sing Ming Chen

Sing's log, a developer's blog

90 posts
259 tags
GitHub E-Mail Linkedin Facebook
© 2024 Sing Ming Chen
Powered by Hexo v3.9.0
|
Theme — NexT.Gemini v6.3.0