Skip to content

Instantly share code, notes, and snippets.

View Haosvit's full-sized avatar

Hao Nguyen Haosvit

  • Netherlands
View GitHub Profile
@Haosvit
Haosvit / Node.js CORS
Created May 20, 2019 14:52 — forked from nilcolor/Node.js CORS
Node.js cross-origin POST. You should response for OPTIONS request first. Something like this.
if (req.method === 'OPTIONS') {
console.log('!OPTIONS');
var headers = {};
// IE8 does not allow domains to be specified, just the *
// headers["Access-Control-Allow-Origin"] = req.headers.origin;
headers["Access-Control-Allow-Origin"] = "*";
headers["Access-Control-Allow-Methods"] = "POST, GET, PUT, DELETE, OPTIONS";
headers["Access-Control-Allow-Credentials"] = false;
headers["Access-Control-Max-Age"] = '86400'; // 24 hours
headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept";
@Haosvit
Haosvit / vscode_git_ssh.bat
Created May 21, 2019 11:28
vscode with git ssh without Permission denied (publickey)
start ssh-agent
start code <project folder path>
@Haosvit
Haosvit / JS|TS Lesson Learned.md
Created July 22, 2019 13:48
#TIL Today I learned...
@Haosvit
Haosvit / AndroidManifest.xml
Created August 11, 2019 08:29
Karamunting.Android.BumpTech.Glide doesn't work
<application
...
android:usesCleartextTraffic="true"
...
/>
@Haosvit
Haosvit / jest_guide.md
Last active August 19, 2021 13:20
Jest technique
  • use Jest Runner extension: [link]

Debug Jest:

ShallowWrapper {
...
Symbol(enzyme.__node__) {
  props: { // use this to search for item with property:value pair. Ex: wrapper.find('MenuItem[title="View"]')
    children: [{}],
    ...others
  },
@Haosvit
Haosvit / solution.md
Created August 12, 2019 20:55
Visual studio keep hanging while include too many files (Android drawables)

remove .sv folder.

@Haosvit
Haosvit / memo.md
Last active August 15, 2019 20:11
Release apk
  1. Build release mode
  2. Archive Adhoc, create keystore
  3. Zip align:
$ <Drive>\Program Files (x86)\Android\android-sdk\build-tools\28.0.3\zipalign
-v -p 4 <apk input> <apk output dir & name>

Demo:

@Haosvit
Haosvit / regex.md
Last active November 14, 2019 12:11
Regex find text in between delimiter

EX: extract text in between title tags:

const htmlText = '<html><title>Example Title</title><body>abc</body></html>`
const regex = /(?<=<title>).*?(?=\</title>)/;
const matches = htmlText.match(regex);
const title = matches && matches.shift();
@Haosvit
Haosvit / writejson.js
Created December 31, 2019 10:32
node write file javascript
function writeFile(fileName, data, indent = 2) {
require('fs').writeFile(`${fileName}`, JSON.stringify(data, '', indent), (err) => {
if (err) {
return console.log(err);
}
console.log(`Done "${fileName}".`);
});
}