2021年10月25日 星期一

[Linux] Check os version in Linux

> cat /etc/os-release

root@58d01b6b8b17:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

2019年8月26日 星期一

[C#, Unity] Unity Text text super box with ‘...’ ellipsis at the end

public void SetTextWithEllipsis(Text textComponent, string value)
        {
            var generator = new TextGenerator();
            var rectTransform = textComponent.GetComponent<RectTransform>();
            var settings = textComponent.GetGenerationSettings(rectTransform.rect.size);
            generator.Populate(value, settings);
            var characterCountVisible = generator.characterCountVisible;
            var updatedText = value;
            if (value.Length > characterCountVisible)
            {
                updatedText = value.Substring(0, characterCountVisible - 3);
                updatedText += "…";
            }
            textComponent.text = updatedText;
        }


Example:

Transform tt = gameObject.transform.Find("Text");
SetTextWithEllipsis(tt.gameObject.GetComponent<Text>(), "fffffffffffffffffffffffff");


中英文 符號 對照

’Apostrophe撇號
() Bracket (英式) / Parentheses (美式)括號
 : Colon冒號
 , Comma逗號
 - Dash破折號
 … Ellipsis省略號
 ! Exclamation Mark (英式) / Point (美式)感嘆號
 . Full Stop (英式) / Period (美式)句號
 《 》 Guillemet書名號
 – Hyphen連字號
?  Question Mark問號
 "" Quotation Mark引號
;  Semicolon分號
/ Slash斜線

2019年8月21日 星期三

[C#, unity] Fixed: The name instantiate' does not exist in the current context

                        Transform cloneTransform = m_fields.GetChild(nColumn).GetChild(nIndex);
                        Transform tempTransform = Instantiate(cloneTransform).transform;
                        tempTransform.SetParent(m_fields.GetChild(nColumn));
                        tempTransform.localPosition = Vector3.zero;
                        tempTransform.localRotation = Quaternion.identity;
                        tempTransform.localScale = Vector3.one;


Answer:

Transform tempTransform = GameObject.Instantiate(cloneTransform).transform;

2019年7月29日 星期一

[C#, Unity] String to Color; Color to String


String to Color
string col = "#FF8400";
this.BackColor = System.Drawing.ColorTranslator.FromHtml(col);


Color to String Color
mycolor = this.BackColor;
string strcol = System.Drawing.ColorTranslator.ToHtml(mycolor);
MessageBox.Show(strcol);

Unity:
public void SetImageColor(string strColor)
{
    Color clr;
    if (ColorUtility.TryParseHtmlString(strColor, out clr))
        this.gameObject.GetComponent<Image>().color = clr;
}

2017年8月15日 星期二

[Linux] How to add a literal tab character in a bash shell?

$'\t'

ex: $ sort -t $'\t'
$ echo -n $'\t'

$ echo -e ' \t ' | hexdump -C
00000000 20 09 20 0a | . .| 00000004

2017年5月15日 星期一

[Linux] How to find all files containing specific text on Linux?

grep -rnw '/path/to/somewhere/' -e 'pattern'
  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.
P.S. example: to find "if ["

grep -rnw '/path/to/somewhere/' -e 'if \['

    2016年7月28日 星期四

    [Linux] Create encrypted (password protected) zip/upzip file

     - zip 

    This will prompt for a password:
    zip --encrypt file.zip files
    
    This is more insecure, as the password is entered/shown as plain text:
    zip --password (password) file.zip files
    

    Warning, the standard zip encryption is very weak and is easily cracked.


    - unzip 

    unzip -P (password) file.zip
    

    2016年3月4日 星期五

    [Linux] How can I get what my main function has returned

    Most shells store the exit code of the previous run command in $? so you can store or display it.
    $ ./a.out
    $ echo $?     # note - after this command $? contains the exit code of echo!
    or
    $ ./a.out
    $ exit_code=$?    # save the exit code in another shell variable.

    [Linux] Checking if a directory exists in Unix (system call)

    #include <sys/stat.h>
    
    struct stat sb;
    
    if (stat(pathname, &sb) == 0 && S_ISDIR(sb.st_mode))
    {
        ...it is a directory...
    }

    2014年7月29日 星期二

    [Xcode] Fixed: Build error that it import Objective-C codes in the .cpp?

    Build error: (NSObjCRuntime.h & NSObject)

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:371:1: Expected unqualified-id

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:373:19: Unknown type name 'NSString'
    ...

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/objc/NSObject.h:11:1: Expected unqualified-id
    ...


    [Solution]
    rename extension name from .cpp into .mm

    [Xcode] Fixed: _CMAudioFormatDescriptionGetStreamBasicDescription", referenced from: -[captureNSObject init] in captureNSObject.o

    I have a project to build some code,  and then it has error in the follow:

    Undefined symbols for architecture x86_64:
      "_CMAudioFormatDescriptionGetStreamBasicDescription", referenced from:
          -[captureNSObject init] in captureNSObject.o
      "_CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer", referenced from:
          -[captureNSObject captureOutput:didOutputSampleBuffer:fromConnection:] in captureNSObject.o
      "_CMSampleBufferGetNumSamples", referenced from:
          -[captureNSObject captureOutput:didOutputSampleBuffer:fromConnection:] in captureNSObject.o
    ld: symbol(s) not found for architecture x86_64

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    [Solution]
    Add CoreMedia.framework into "Linked Frameworks and Libraries".

    2014年7月24日 星期四

    [Xcode] Enable/disable a button

    @property (retain, nonatomic) IBOutlet UIButton *btnButton;
    enable/disable like this in .m file:
    btnButton.enabled = NO; // disable button
    btnButton.enabled = YES; // enable button

    2014年7月16日 星期三

    [Xcode] How to quit the application when the window closes

    If you want an application to quit (terminate) when the window is closed, you can do this:

    -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)theApplication
    {
        return YES;
    }

    2014年7月14日 星期一

    [Xcode] How to convert between NSTextField and NSString

    // NSString --> NSTextField
    NSTextField * txtField = [[NSTextField alloc] init];
    NSString *str = @“1234”;
    txtField.stringValue = str;

    // NSTextField --> NSString
    NSString *str1 = txtField.stringValue;

    [Xcode] How to convert byte array to NSString

    Byte* btData = new Byte[12];
    memset(btData, 0, sizeof(Byte) * 12);
    ...

    NSData *data = [NSData dataWithBytes:btData length:sizeof(btData)];
    NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];