Showing posts with label Lập trình. Show all posts
Showing posts with label Lập trình. Show all posts

Feb 26, 2019

Quora - Một lập trình viên chuyên nghiệp có thường xuyên sử dụng Google trong khi code không?

Trả lời: Brian Knapp, Christian, Software Engineer. I blog at Code Career Genius

Một hôm, tôi đang ngồi uống cà phê với một trong những người bạn thân nhất của tôi, một lập trình viên xuất sắc. Anh ấy đã kể cho tôi một vài điều thú vị.
"Mày biết không, tao không nghĩ rằng hầu hết mọi người đều tò mò."
Tôi tò mò và yêu cầu hắn ta giải thích.
"Ờ thì, rất nhiều người xung quanh tao thậm chí không thể biết cách tìm kiếm trên Google."
Tôi đã thực sự sửng sốt.
Hắn ta đã giải thích rằng rất nhiều lần mọi người sẽ hỏi hắn ta những điều mà hắn chỉ cần search Google câu trả lời rồi nói lại với họ. Hắn ta điều hành một công ty phần mềm nhỏ và đã phải gỉai thích điều này với người của mình.
Tôi choáng váng.
Và rồi hắn nói về việc bạn bè và người thân hắn thường không có đủ sự tò mò để có thể tự tìm kiếm bất cứ điều gì cho chính họ trên Google, trong sách hay bất cứ cái gì khác.
Nói qua một chút, cả tôi và hắn đọc rất nhiều sách, viết rất nhiều code và dành hàng giờ liền mỗi ngày để Google. Cả hai chúng tôi đều thành công, là những chuyên gia lập trình ở thời điểm này.
Đó là một cuộc trò chuyện khai sáng và cả hai chúng tôi cùng đi đến kết luận rằng một trong những siêu năng lực thực sự của chúng tôi là khả năng sử dụng Google, sách hay những nguồn thông tin khác để giải quyết vấn đề. Và rồi.. cả hai chúng tôi đều có đủ sự tò mò để làm điều đó cho chính mình.
Một người bình thường thậm chí không đủ tò mò để lên Quora và đặt câu hỏi. Bây giờ, bạn có thể nghĩ rằng điều đó thật điên rồ (là bạn đang đọc cái này trên Quora) nhưng hãy xem xét thực tế siêu thú vị này.
Một nhà văn nổi tiếng bán hàng ngàn cuốn sách. hoặc có thế hàng chục, hàng trăm ngàn cuốn sách.
Một người trả lời nổi tiếng trên Quora nhận được hàng triệu lượt xem bài viết, nhưng một nhân vận truyền hình hay điện ảnh nổi tiếng sẽ được xem và lắng nghe hàng tỉ tỉ lần.
Ví dụ như loạt phim The Avengers, chúng đã được xem hàng tỉ lần tính tới thời điểm này.
Đó là một cách nói dài dòng rằng mọi người thà ngồi xem phim hay chương trình truyền hình còn hơn là làm bất cứ gì khác khi họ rảnh.
Vì vậy, hầu hết mọi người gần như không có đủ tò mò như là khi họ ngồi xem truyền hình hay phim.
Tuy nhiên, số ít người tò mò về mọi thứ có lợi thế rất lớn về kiến thức so với những người bình thường khác. Trong khi những người khác đang giải trí, những người tò mò đang sử dụng Google, Youtube.. để học mọi thứ và giải quyết vấn đề, và cuối cùng cải thiện cuộc sống của họ.
Lập trình viên cũng không ngoại lệ với điều này. Những người tò mò sử dụng Google nhiều hơn những lập trình viên không tò mò. Vì thế, họ sẽ có được lợi thế về kiến thức và có nhiều khả năng trở thành những chuyên gia.
Những người trong chúng tôi đã đạt đến trình độ chuyên gia trong lĩnh vực phát triển phần mềm đều có hiệu quả khá cao trong việc sử dụng Google, Stackoverflow và sách truyền thống khác để xây dựng lợi thế kiến thức cho mình.
Tại thời điểm này trong lịch sử, lợi thế tri thức đó là vô cùng quý giá.

Nguồn: https://qr.ae/TUfqns

Feb 4, 2019

Quora - Những game như FIFA14 hay GTA5 được viết bằng ngôn ngữ lập trình nào?

Trả lời: Alec Menke, I've been programming for over 10 years.

Rockstar, nhà sản xuất của GTA V, đã tự xây dựng game engine độc quyền cho riêng mình, được gọi là Rockstar Advanced Game Engine (RAGE).
Tôi đoán rằng họ đã xây dựng game engine của mình bằng cách kết hợp C và C++,  và sau đó tiếp tục sử dụng C++ (có thể Javascript với V8) ở các tầng trên game engine để xây dựng các tính năng dành riêng cho từng trò chơi khác nhau.
Sau khi thực hiện nhiều tìm kiếm, nghiên cứu ở trên Internet, tôi có thể kết luận rằng luận điểm ban đầu của tôi đã đúng, tuy nhiên có lẽ họ cũng sử dụng C# trong các server nhiều người chơi của họ. Trong: ngôn ngữ nào đã được sử dụng để lập trình GTA IV?
Để biết thêm thông tin về cách họ mô hình hoá thành phố trong GTA, có thể đọc thêm câu trả lời của Manish Sharma.

Chú thích:
[1] Rockstar Advanced Game Engine
[2] Rockstar Advanced Game Engine
[3] Development of Grand Theft Auto V

Nguồn: https://qr.ae/TUrNil

Jan 23, 2019

Ghi chú về Interface trong Java

# Java Compiler thêm từ khóa publicabstract trước phương thức của interface và các từ khóa public, staticfinal trước các thành viên dữ liệu.

# Một interface không phải là một lớp. Một lớp mô tả các thuộc tính và hành vi của một đối tượng. Một interface chứa các hành vi mà một class triển khai.

Trừ khi một lớp triển khai interface là lớp trừu tượng abstract, còn lại tất cả các phương thức của interface cần được định nghĩa trong class.

Bạn không thể khởi tạo một interface.

Một interface không chứa bất cứ hàm contructor nào.

Tất cả các phương thức của interface đều là abstract.

Một interface không thể chứa một trường nào trừ các trường vừa static và final.

Một interface không thể kế thừa từ lớp, nó được triển khai bởi một lớp.

Một interface có thể kế thừa từ nhiều interface khác.

# Interface được bổ sung thêm Default MethodStatic Method trong Java 8!!!
Chúng giúp chúng ta mở rộng interface mà không phải lo ngại phá vỡ các class được implements từ nó.

Oct 3, 2018

Setup NODE.JS and NPM install behind a web proxy

Check your settings with:
npm config list

Settings behind a proxy:
npm config set registry http://registry.npmjs.org/
npm config set http-proxy http://username:password@ip:port
npm config set https-proxy http://username:password@ip:port
npm config set proxy http://username:password@ip:port
npm set strict-ssl false


Mar 19, 2018

Detect Back to Previous Screen on StackNavigator - React Native

//screen A go to screen B, then back
 
//screenA 
import {DeviceEventEmitter} from "react-native"
componentWillMount() {
    DeviceEventEmitter.addListener('YOUR_LISTENER', (e)=>{})
}

//screenB
DeviveEventEmitter.emit("YOUR_LISTENER",  {})

Mar 15, 2018

React Native Sound


// INSTALL
1. npm install react-native-sound --save
   react-native link react-native-sound
// RESOURCE
2. Add file "yoursound.mp3" to Resources folder in iOS XCode project
// CODE 
3. import Sound from "react-native-sound";
4. constructor(props) {
      super(props); 
      Sound.setCategory("Playback");
      mSound = new Sound("yoursound.mp3", Sound.MAIN_BUNDLE); 
   }
5. _playSound() {
      mSound.play(success => {
         if (success) {
            console.log("Success");
         } else {
            console.log("Failure");
            mSound.reset(); 
         } 
      });
 
https://github.com/hu2di/react-native-mosquito-sound

React Native: Delete Installed Library

1. rnpm unlink package_name (if library with native content requires linking)
2. npm uninstall --save package_name 

Nov 17, 2017

Android: Context

The common actions you can safely take with a given Context object depends on where it came from originally.  Below is a table of the common places an application will receive a Context, and in each case what it is useful for:


Application Activity Service ContentProvider BroadcastReceiver
Show a Dialog NO YES NO NO NO
Start an Activity NO1 YES NO1 NO1 NO1
Layout Inflation NO2 YES NO2 NO2 NO2
Start a Service YES YES YES YES YES
Bind to a Service YES YES YES YES NO
Send a Broadcast YES YES YES YES YES
Register BroadcastReceiver YES YES YES YES NO3
Load Resource Values YES YES YES YES YES
  1. An application CAN start an Activity from here, but it requires that a new task be created.  This may fit specific use cases, but can create non-standard back stack behaviors in your application and is generally not recommended or considered good practice.
  2. This is legal, but inflation will be done with the default theme for the system on which you are running, not what’s defined in your application.
  3. Allowed if the receiver is null, which is used for obtaining the current value of a sticky broadcast, on Android 4.2 and above. 
Read more...

Aug 14, 2017

SimpleDateFormat

Letter  Date or Time Component  Presentation    Examples
G       Era designator          Text                AD
y       Year                    Year                1996; 96
M       Month in year           Month               July; Jul; 07
w       Week in year            Number              27
W       Week in month           Number              2
D       Day in year             Number              189
d       Day in month            Number              10
F       Day of week in month    Number              2
E       Day in week             Text                Tuesday; Tue
a       Am/pm marker            Text                PM
H       Hour in day (0-23)      Number              0
k       Hour in day (1-24)      Number              24
K       Hour in am/pm (0-11)    Number              0
h       Hour in am/pm (1-12)    Number              12
m       Minute in hour          Number              30
s       Second in minute        Number              55
S       Millisecond             Number              978
z       Time zone               General time zone   Pacific Standard Time; PST; GMT-08:00
Z       Time zone               RFC 822 time zone   -0800 

Jun 22, 2017

launchMode in Android

<activity android:launchMode = ["standard" | "singleTop" | "singleTask" | "singleInstance"] ../>

May 18, 2017

Android Color Opacity

Hex Opacity Values:
Ex: Black with 60%: <color name="black">#99000000</color>
100%  FF
95%  F2
90%  E6
85%  D9
80%  CC
75%  BF
70%  B3
65%  A6
60%  99
55%  8C
50%  80
45%  73
40%  66
35%  59
30%  4D
25%  40
20%  33
15%  26
10%  1A
5%  0D
0%  00

Apr 1, 2017

Generate Key Hash for Facebook android

private void getKeyHash() {
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "your Application Id",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Mar 31, 2017

Android: Get real path from URI

public String getRealPathFromURI(Context context, Uri contentUri) {
    Cursor cursor = null;
    try {
        String[] proj = {MediaStore.Images.Media.DATA};
        cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

Update your app to take advantage of the larger aspect ratio on new Android flagship devices

To deliver more engaging viewing experiences to their users, many Android OEMs are experimenting with new, super widescreen smartphones. Samsung has just announced a new flagship device, the Samsung Galaxy S8, featuring a new display format with an aspect ratio of 18.5:9. At the Mobile World Congress earlier this year, LG also launched their new flagship device, the LG G6, with an expanded screen aspect ratio of 18:9.
(Left) An app with a maximum aspect ratio set at 16:9 on an 18.5:9 device 
(Right) An app with a maximum aspect ratio set at or over 18.5:9 on an 18.5:9 device

In order to take full advantage of the larger display formats on these devices, you should consider increasing your app's maximum supported aspect ratio. To do so, simply declare an android.max_aspect <meta-data> element in the app's <application> element:
          <meta-data android:name="android.max_aspect"
                             android:value="ratio_float"/> 
Where ratio_float is the maximum aspect ratio your app can support, expressed as (longer dimension / shorter dimension) in decimal form.
We recommend that you design your app to support aspect ratios of 2.1 or higher. For this, you would add the following to the <application> element:
           <meta-data android:name="android.max_aspect"
                              android:value="2.1" />
Note: if you don't set a value, and android:resizeableActivity is not true, then the maximum aspect ratio defaults to 1.86 (roughly 16:9) and your app will not take advantage of the extra screen space.
As more super widescreen Android devices, like the Samsung Galaxy S8 and the LG G6, become available, you'll have more opportunities to display more content and create more engaging experiences with your app.
For more details about how to support multiple screens on Android, please visit the page Supporting Multiple Screens.

Mar 30, 2017

substring() in Java

Example:

public class MySubString {  
     public static void main(String args[]) {  
          String s1="HuyHung";  
          System.out.println(s1.substring(2,4));//return yH
          System.out.println(s1.substring(2));  //return yHung  
     }
} 

Mar 29, 2017

Android: List videos on device (MediaStore)

public static void printNameOfVideos(Context context) {
    Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    String[] projection = { MediaStore.Video.VideoColumns.DATA };
    Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
    int vidsCount = 0;
    if (c != null) {
        vidsCount = c.getCount();
        while (c.moveToNext()) {
            Log.d("VIDEO", c.getString(0));
        }
        c.close();
    }
}

Mar 24, 2017

Android: Shared Preference: apply() vs commit()


  • apply() was added in 2.3, it commits without returning a boolean indicating success or failure. apply() schedules the data to be written asynchronously. It does not inform you about the success of the operation.
  • commit() returns true if the save works, false otherwise. commit() writes the data synchronously (blocking the thread its called from). It then informs you about the success of the operation.
  • apply() was added as the Android dev team noticed that almost no one took notice of the return value, so apply is faster as it is asynchronous.

Design Pattern: Bạn muốn truyền đối số vào Singleton?

    Một singleton, được định nghĩa, là một đối tượng mà bạn muốn được khởi tạo không quá một lần. Nếu bạn muốn truyền tham số vào phương thức khởi tạo, thì nó không còn là singleton nữa.
    Do đó, bạn có hai lựa chọn:
 
    Nếu bạn muốn singleton của bạn được khởi tạo với một số dữ liệu, bạn có thể nạp nó với dữ liệu sau khi khởi tạo, giống như:
Singleton singleton = Singleton.getInstance(); singleton.init(paramA, paramB); // init the object with data

    Nếu tham số cần truyền vào thay đổi khác nhau mỗi lần, bạn có thể truyền tham số vào mỗi lần gọi hàm muốn thực hiện:
Singleton singleton = Singleton.getInstance();
singleton.doSomething(paramA, paramB); // pass parameters on execution

Design Pattern: Singleton

class Singleton {
    private static final Singleton ourInstance = new Singleton();

    static Singleton getInstance() {
        return ourInstance;
    }

    private Singleton() {
    }
}