Skip to content

Instantly share code, notes, and snippets.

View syafiqfaiz's full-sized avatar

syafiq faiz syafiqfaiz

View GitHub Profile
@syafiqfaiz
syafiqfaiz / 4 fundamentals in programming.js
Created August 30, 2023 15:36
mentorship fundamental JS
// fundamental of any progamming langguage
1) variables
var namaVar = 'fikri'
let namaLet = 'fikri'
const namaConst = 'fikri'
const umur = 20
const biodata = {
tarikh_lahir: '20-10-1999',
@syafiqfaiz
syafiqfaiz / dump.sql
Last active August 23, 2023 12:41
SQL dump for sql introduction class
DROP TABLE IF EXISTS "public"."todo_items";
-- This script only contains the table creation statements and does not fully represent the table in the database. It's still missing: indices, triggers. Do not use it as a backup.
-- Sequence and defined type
CREATE SEQUENCE IF NOT EXISTS todo_items_id_seq;
-- Table Definition
CREATE TABLE "public"."todo_items" (
"id" int4 NOT NULL DEFAULT nextval('todo_items_id_seq'::regclass),
"text" text,
@syafiqfaiz
syafiqfaiz / people.rb
Last active June 27, 2023 02:46
How to use Google People V1 API using service acccount in Ruby.
require 'google/apis/people_v1'
require 'googleauth'
# Set up authorization
scopes = ['https://www.googleapis.com/auth/contacts']
credentials = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('g_suite_service_account.json'),
scope: scopes,
)
credentials.sub = '[email protected]'
@syafiqfaiz
syafiqfaiz / Blocking IO
Last active April 9, 2023 08:49
Node blocking and non blocking IO
const fs = require('fs');
console.log('hi 1')
const data = fs.readFileSync('./file.md', 'utf8'); // blocks here until file is read
console.log(data);
console.log('hi 3')
@syafiqfaiz
syafiqfaiz / Node JS Hello World
Created April 9, 2023 08:35
Simple Server with just node js
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(5000); //the server object listens on port 8080
// Console will print the message
console.log('Server running at 5000');
@syafiqfaiz
syafiqfaiz / contoh github actions
Created May 9, 2021 01:12
contoh github action utk deploy node
name: Deploy Node
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
@syafiqfaiz
syafiqfaiz / Filterable.rb
Created June 14, 2019 03:05
A module to make a clean and simple filtering
module Filterable
extend ActiveSupport::Concern
module ClassMethods
def filter(filtering_params)
results = self.where(nil)
filtering_params.each do |key, value|
results = results.public_send(key, value) if value.present?
end
results
@syafiqfaiz
syafiqfaiz / how-to-copy-aws-rds-to-local.md
Last active August 22, 2025 13:56
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored