Skip to content

Instantly share code, notes, and snippets.

View hungneox's full-sized avatar
✌️

Hung Neo hungneox

✌️
View GitHub Profile
@hungneox
hungneox / models.py
Created July 19, 2023 09:18 — forked from morenoh149/models.py
Django model method mocking
class Blog(django.model):
name = models.CharField(null=False, max_length=64)
def list_articles(self):
return [
{'body': 'abcdefg'},
{'body': 'abcdefg'},
{'body': 'abcdefg'},
]
@hungneox
hungneox / knex_ssl.md
Created March 2, 2022 12:37 — forked from zmts/knex_ssl.md
Can't connect to PostgreSQL. SSL error with Nodejs/Knexjs (Digital ocean)

Can't connect to PostgreSQL. SSL error with Nodejs/Knexjs (Digital ocean)

Issues:

Case 1

{
  client: 'pg',
  connection: {
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
@hungneox
hungneox / DI.py
Created August 12, 2021 15:01 — forked from elnygren/DI.py
Functional Dependency Injection in TypeScript
# dataclass saves the trouble of writing __init__ implementations
# frozen=True makes the class instances immutable (so no hidden mutable state)
@dataclass(frozen=True)
class UserConnector:
def get_user(id: str) -> User:
return User.objects.get(id=id)
@dataclass(frozen=True)
class OrgConnector:
def get_org(id: str) -> Org:
@hungneox
hungneox / axiosInterceptor.js
Created March 30, 2021 08:32 — forked from VassilisPallas/axiosInterceptor.js
Axios interceptor that handled the error response and uses the cancel signal in every request
import axios from 'axios';
let signal = axios.CancelToken.source();
/**
* returns if error is being caused by axios cancel
* @function
* @returns {Boolean} - true if the error caused by canceling the request
*/
const areRequestsCanceled = err => {
@hungneox
hungneox / nodejs-tcp-example.js
Created March 19, 2021 22:09 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@hungneox
hungneox / dijkstra.js
Created December 17, 2020 05:09 — forked from stella-yc/dijkstra.js
Dijkstra's Algorithm in Javascript using a weighted graph
const problem = {
start: {A: 5, B: 2},
A: {C: 4, D: 2},
B: {A: 8, D: 7},
C: {D: 6, finish: 3},
D: {finish: 1},
finish: {}
};
const lowestCostNode = (costs, processed) => {
@hungneox
hungneox / spacemacs-cheatsheet.txt
Created April 28, 2020 07:22 — forked from k3yavi/spacemacs-cheatsheet.txt
Spacemacs cheatsheet
//from http://www.saltycrane.com/blog/2015/12/switching-emacs-vim-actually-spacemacs/
Useful Spacemacs commands
SPC q q - quit
SPC w / - split window vertically
SPC w - - split window horizontally
SPC 1 - switch to window 1
SPC 2 - switch to window 2
SPC w c - delete current window

Creating your own Native Modules

Sometime when we need a specific way to interact with the phone or operator system which is various different between iOS and Android, that when we need to lean that responsibility to the OS it self.

In RN, most of the logic and UI, in the best way, must be consistent between platforms. So, In an advance level of bringing best user experience to end user, we need to create native module, that mean the leaning the logic to the Native Part. There are ton of article out there showing why and when we need to create a native module, I won't dive into explanation again. Instead, I will show you how can we create a native module that could be used in React native code. That mean, you write your Objective-C/Java code, and import and run it as a module in Javascript Code.

I will show you here the most basic way to create the most basic library, called: open https://google.com. It means, I want to open Google by using the default iOS/Android browser in a native way.

Creating re

@hungneox
hungneox / README.md
Created February 11, 2020 10:18 — forked from twolfson/README.md
Setting up SOPS

I'm learning about SOPS and setting it up as my preferred mechanism for storing secrets. Here are my notes.

PGP

It’s security mechanism is that we (i.e. client) use a PUBLIC key from the receiver (i.e. server) and encode it with a random key (I’m saying nonce but it could be reused)

This varies from RSA and SSH because the server uses a PUBLIC key to identify the client.

Web of trust

Web of trust operates by still using PGP (i.e. encoding with recipient’s public key) but additionally, we can encrypt/sign the data as our own by signing it with the client’s private key.

This means the recipient will initially decrypt via our (i.e. client’s) public key (verifying the source) and then decrypting via their (i.e. server’s) private key to get the data.

@hungneox
hungneox / nginxproxy.md
Created January 12, 2020 13:37 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers