Skip to content

Instantly share code, notes, and snippets.

View liuxd's full-sized avatar
🗿
Hi, there.

Allen Liu liuxd

🗿
Hi, there.
  • Tax Traders
  • Auckland, New Zealand
View GitHub Profile
@liuxd
liuxd / demo.html
Created July 1, 2019 23:32
[Prevent Negative values in number input]
<input type="number" min="0" oninput="this.value = Math.abs(this.value)">
@liuxd
liuxd / set_tz.py
Created April 14, 2019 22:17
[Set time zone in Python3]
import os, time
os.environ['TZ'] = 'Pacific/Auckland'
time.tzset()
@liuxd
liuxd / guild.md
Created April 4, 2019 02:57
[Connecting DBeaver to a Heroku Postgres Database] #PostgreSQL #Heroku

To connect Pgsql in Heroku, SSL is required. If not, an error message will be given:

FATAL: no pg_hba.conf entry for host "75.168.4.146", user "rphbqggxeokuxl", database "dc008iqk0rq4j5", SSL off

To make it with DBeaver:

  • click the "SSL" tab on connection proper.
  • choose a Factory for "SSL Factory" in the "Advanced" section.
@liuxd
liuxd / sample.js
Created December 4, 2018 21:38
[array_merge() in JS]
// for array
let arr1 = ['a', 'b'], arr2 = ['c'];
console.log(arr1.concat(arr2)); // ['a', 'b', 'c']
// for object
let obj1 = {'a': 1, 'b': 2}, obj2= {'c': 3, 'a': 4}
console.log(Object.assign(obj1, obj2)) // {a: 4, b: 2, c: 3}
@liuxd
liuxd / sample.js
Created December 4, 2018 21:17
[is_array() in JS]
var a = [], b = {};
console.log(Array.isArray(a)); // true
console.log(Array.isArray(b)); // false
@liuxd
liuxd / sample.js
Last active December 4, 2018 21:15
[is_numeric() in JS]
var t1 = 100, t2 = '100', t3 = 'test';
console.log(isNaN(t1)); // false
console.log(isNaN(t2)); // false
console.log(isNaN(t3)); // true
@liuxd
liuxd / content.md
Last active June 20, 2024 23:08
[#14 As a Veteran Coder] #編程之道

As a Veteran Coder

2017-05-25

On October the first 2009, I became a professional programmer. That was the very beginning of my coding career. Util now, 2016, seven years has gone. I think it is necessary to write something to review what I have learnt.

Role. Speaking of the nature of programmers, I consider them as the problem solvers and data players. Usually, programmers are called software engineers who concentrate on the problem in real world instead of the abstract theories like the scientists. And how do they solve the problems? They just operate the data in the computers. The data, including the program itself, actually consists of 1 and 0. That is the real pattern which computer can recognize the data, but not readable for people, so we need build a number of layers to make the data readable for people. In my opinion, programming languages are the certain bridges to computers and operating systems play an important role by translating the programming language to 1 and 0 which computers can

@liuxd
liuxd / code.php
Created October 8, 2018 01:05
[Calculating days of week given a week number]
<?php
$week_number = 40; // If the number is less than 10, use '0' as the prefix, eg: 03.
$year = 2008;
for($day=1; $day<=7; $day++)
{
echo date('m/d/Y', strtotime($year."W".$week_number.$day))."\n";
}
@liuxd
liuxd / code.sql
Last active March 7, 2019 21:34
[Datetime to date] #MSSQL
SELECT CONVERT(date, LastLoginDate) FROM dbo.VCUsers
@liuxd
liuxd / sample.sql
Last active March 7, 2019 21:35
[FOR JSON AUTO] #MSSQL
SELECT *
FROM test
FOR JSON AUTO;