Skip to content

Instantly share code, notes, and snippets.

View dylansalim3's full-sized avatar
🎯
Focusing

Dylan Lim dylansalim3

🎯
Focusing
View GitHub Profile
class CustomAppBar extends PreferredSize {
final Widget child;
final double height;
CustomAppBar({@required this.child, this.height = kToolbarHeight});
@override
Size get preferredSize => Size.fromHeight(height);
@override
@dylansalim3
dylansalim3 / gist:e7b9dda2b59957a01b5625f1450669d4
Created September 7, 2020 08:29
LIst of security Questions
const List<String> SECURITY_QUESTIONS = [
"What city were you born in?",
"What is your favorite food?",
"Where did you go to high school?",
"What was the first company that you worked for?",
"What was the name of your first pet?",
"What is the name of the road you grew up on?",
"What is your mother’s maiden name?",
"What Is your favorite book?",
"Where is your favorite place to vacation?",
@dylansalim3
dylansalim3 / sequelize_sample.js
Created September 13, 2020 09:56
Sample transaction query in sequelize
// Sample 1
db.sequelize.transaction(t => {
var promises = [];
for (let i = 0; i < usersData.length; i++) {
promises[i] = UserRepository.createUser(usersData[i], {transaction: t});
}
return Promise.all(promises).then(users => {
var userRolePromises = [];
for (var i = 0; i < users.length; i++) {
userRolePromises.push(UserRole.create({
@dylansalim3
dylansalim3 / sequelize_transaction_sample.js
Created September 13, 2020 14:11
Sequelize Transaction sample
const t = await db.sequelize.transaction();
const promises = [];
for (let i = 0; i < usersData.length; i++) {
promises[i] = UserRepository.createUser(usersData[i], {transaction: t});
}
Promise.all(promises).then(users => {
const userRolePromises = [];
for (let i = 0; i < users.length; i++) {
userRolePromises.push(RoleRepository.findRoleById(rows[users[i].email]).then(role => {
users[i].addRole(role);
//One to One
bookDetail.hasOne(category);
category.belongsTo(bookDetail);
//One to Many
borrowBook.belongsTo(user,{foreignKey: 'user_id',});
user.hasMany(borrowBook,{foreignKey: 'user_id',});
//Many to Many
bookDetail.belongsToMany(author,{through: "book_author",foreignKey:'book_detail_id'});
@dylansalim3
dylansalim3 / kill_port_process.sh
Last active November 22, 2020 16:39
kill process associated to the port (linux)
sudo fuser -n tcp -k {port_number}
// in cmd
netstat -aon | find "PORT_NUM"
// In bash:
netstat -na | grep "8080"
// In PowerShell:
netstat -na | Select-String "8080"
Sample Output:
@dylansalim3
dylansalim3 / create_bootable_iso.sh
Created November 22, 2020 16:37
Create bootable usb through Linux terminal (ONLY FOR LINUX ISO)
//check dev id
sudo fdisk -l
sample output:
Disk /dev/sdc: 14.3 GiB, 15376000000 bytes, 30031250 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
//Unmount the usb
// Build docker file with a given tag
docker build -t {tag-name} {docker-location}
example -> docker build -t node-app-test .
//run docker in interactive mode
docker run -it -p {exposed-machine-port}:{application-port} {tag-name}
example -> docker build -t 9000:3000 node-app-text
// run container in the background/detach mode
docker run -d -p {exposed-machine-port}:{application-port} {tag-name}
@dylansalim3
dylansalim3 / angular_webworker.md
Last active March 16, 2021 09:23
Web Worker Example in Angular

Web Worker in Angular

Example 1: Fibonacci Function in Angular

Create a web worker
ng generate web-worker webWorker

and move the fibonacci function into the file:

// webWorker-demo/src/app/webWorker.ts
function fibonacci(num) {
    if (num == 1 || num == 2) {