Skip to content

Instantly share code, notes, and snippets.

View kennethteh90's full-sized avatar

Kenneth Teh kennethteh90

View GitHub Profile
class OtpLoginController < ApplicationController
def request_otp
user = otp_user
user.send_otp
render json: {}, status: 200
end
def otp_login
user = otp_user
raise SomeError unless user.verify_otp(params[:otp])
module Otp
def send_otp
result = sms_client.sms.send(
from: 'Us',
to: "+65#{mobile_number}",
text: "Your one time password is #{otp}"
)
raise SomeError unless result.messages[0].status == '0'
end
requestPdf() {
axios.request({
url: someUrl,
method: 'POST',
responseType: 'blob',
params: {
someParam: someParam
}
})
.then(response => response.data)
def pdf
rendered_pdf = SomePrawnPdfDocument.new(params, view_context).render
send_data(
rendered_pdf,
type: 'application/pdf',
disposition: 'inline'
)
end
@kennethteh90
kennethteh90 / clear_redis_script.rb
Created January 20, 2020 03:03 — forked from brasic/clear_redis_script.rb
Clear a large number of redis keys by pattern using SCAN and pipelining
#!/usr/bin/env ruby
require 'redis'
# Clear a large number of keys matching a pattern using SCAN and
# pipelining to avoid killing the server.
class ClearKeys
def initialize(pattern, host='localhost', postprocess_pattern=nil)
@redis = Redis.new(host: host)
@pattern = pattern
@kennethteh90
kennethteh90 / exportDatabase.js
Created November 12, 2019 08:44
Function for exporting GCP Postgres database to Google Cloud Storage
const {google} = require("googleapis");
const {auth} = require("google-auth-library");
var sqladmin = google.sqladmin("v1beta4");
exports.exportDatabase = (_req, res) => {
async function doIt() {
const authRes = await auth.getApplicationDefault();
let authClient = authRes.credential;
var request = {
// Project ID of the project that contains the instance to be exported.

Welcome to Kenneth Teh's Github Map!

This is a map of my Github. You can skip to the repos here (GitHub Page) or read on for an overview of my projects.

Projects

My side projects
  • Guest Tracking System (Rails) - this simple app solved an annoying problem for us in church. Basically, we were using a group chat for our host team to keep track of new guests in church, but the issue was that we didn't have a common list that could be added to or edited. Instead, we were manually copying and pasting previous lists, then adding to/editing them. Blog post here.
  • Birthday/Event Reminder App (Google Apps Script) - wrote a few lines of code to make my initial 'app' accessible to non-coders. This app sends reminder messages to a chat group through the Telegram bot API.
Rails