profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/donjar/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.
Herbert Ilhan Tanujaya donjar Traverse Technologies Singapore herbert.id NUS Computer Science + Pure Mathematics alumni, building (or breaking) a bunch of random stuff 🔨

donjar/greeting-todo 2

A todo list in Fish's greeting message

donjar/Awesome-CV 1

Awesome CV is LaTeX template for your outstanding job application

donjar/ctf-solutions 1

Solutions to various CTF challenges online

donjar/cvwo-assignment-1 1

Test website for CVWO Assignment 1.

donjar/dotfiles 1

My dotfiles!

donjar/addressbook-level4 0

Address Book sample application (Level 4)

donjar/advent-of-code-2017-rust 0

Advent of Code 2017, done in Rust!

donjar/angular 0

https://angular.io/docs/js/latest/quickstart.html

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

   %w[terms syarat ketentuan].each { |r| get "/#{r}", to: 'home#terms' }   %w[contact kontak hubungi].each { |r| get "/#{r}", to: 'home#contact' } +  get '/unsubscribe/:token', to: 'user_notifications#unsubscribe', as: :unsubscribe

You need the user_id right? When you construct the route, you ought to have the user_notification object because you have the token. So I'm saying that you can get the user_id from the user_notification object.

nugriz

comment created time in 4 days

PullRequestReviewEvent

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

   %w[terms syarat ketentuan].each { |r| get "/#{r}", to: 'home#terms' }   %w[contact kontak hubungi].each { |r| get "/#{r}", to: 'home#contact' } +  get '/unsubscribe/:token', to: 'user_notifications#unsubscribe', as: :unsubscribe

You have the user notification right? Can't you just do user_notification.user_id?

nugriz

comment created time in 4 days

PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 module Mailgun   def send_message(**params)     make_valid!(params)     text = params[:text]+    stop_this_notification_url = params[:stop_this_notification_url]+    unsubscribe_url = params[:unsubscribe_url]     params[:text] = Social.email_template.get binding
params[:text] = params[:unsubscribe_url].present? ? Social.email_template_with_unsubscribe_link.get binding : Social.email_template.get binding

Something like this?

nugriz

comment created time in 12 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

+- content_for :page_attributes do

Why is this an exact copy of the welcome view?

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

+- content_for :page_attributes do

Why is this an exact copy of the welcome view?

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 module Mailgun   def send_message(**params)     make_valid!(params)     text = params[:text]+    stop_this_notification_url = params[:stop_this_notification_url]+    unsubscribe_url = params[:unsubscribe_url]     params[:text] = Social.email_template.get binding

Use an if statement?

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 module Mailgun   def send_message(**params)     make_valid!(params)     text = params[:text]+    stop_this_notification_url = params[:stop_this_notification_url]+    unsubscribe_url = params[:unsubscribe_url]     params[:text] = Social.email_template.get binding+    params[:text] = Social.email_template_with_unsubscribe_link.get binding if params[:unsubscribe_url].present?

Check if params[:stop_this_notification_url] also exists?

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

   %w[terms syarat ketentuan].each { |r| get "/#{r}", to: 'home#terms' }   %w[contact kontak hubungi].each { |r| get "/#{r}", to: 'home#contact' } +  get '/unsubscribe/:token', to: 'user_notifications#unsubscribe', as: :unsubscribe

Can you look into the patterns above and use them? i.e. resources, collection, etc.

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def feedback_ending(time_text)                        .pluck(:user_id))      Ajat.info "feedback_ending|id:#{@contest.id}|time:#{time_text}"-    send_emails(text: text, subject: subject, users: users)+    send_emails(text: text, subject: subject, users: users, event: 'feedback_ending')   end    private def send_emails(**hash)-    hash[:users].pluck(:email).each_slice(200) do |arr|+    hash[:users].pluck(:email).each do |email|+      user_id = User.find_by(email: email).id+      notification_id = Notification.find_by(event: hash[:event]).id+      user_notification = UserNotification.where(user_id: user_id).find_by(notification_id: notification_id)+      unsubscribe_link = unsubscribe_url token: user_notification.generate_token

I think a better design would be to generate the token automatically before UserNotification create. That way we can set UserNotification to be non-nullable, and we can just do user_notification.token here instead of user_notification.generate_token.

That way, when someone else wants to use the UserNotification's token, they would not need to do the hassle of generating the tokens themselves, as it would have been auto generated.

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end++  def unsubscribe+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      Notification.find_each do |n|+        notif = UserNotification.find_by(+          user_id: user_notif.user_id, notification_id: n.id+        )+        notif.destroy! if notif.present?+      end+    end+    flash.now[:alert] = 'Anda telah unsubscribe email KTOM'+  end++  def stop_this_notification+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      notif = UserNotification.find_by(+        user_id: user_notif.user_id, notification_id: params[:notification_id]

If the token already uniquely identifies a UserNotification object, what is the use of this notification_id?

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

+- content_for :page_attributes do

Why is this an exact copy of the welcome view?

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end+

Can you come up with better names for these functions?

  • unsubscribe can also apply to the other function.
  • stop_this_notification isn't very clear either. What notification is it talking about?

If someone new to the codebase reads these function names, we want it to be easy for the reader to distinguish between these two names.

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end++  def unsubscribe+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      Notification.find_each do |n|+        notif = UserNotification.find_by(user_id: user_notif.user_id, notification_id: n.id)+        notif.destroy! if notif.present?+      end+    end+    flash.now[:alert] = 'Anda telah unsubscribe email KTOM'
    flash.now[:alert] = 'Anda telah unsubscribe email KTOM.'
nugriz

comment created time in a month

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end++  def unsubscribe+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      Notification.find_each do |n|+        notif = UserNotification.find_by(

Can you come up with better variable names than n, notif, user_notif?

By itself usually these variables are not a problem. When they are mixed together, though, they can be confusing to differentiate.

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def contest_starting(time_text)     users = notif.users      Ajat.info "contest_starting|id:#{@contest.id}|time:#{time_text}"-    send_emails(text: text, subject: subject, users: users)+    send_emails(text: text, subject: subject, users: users, event: 'contest_starting')

Can you use a symbol instead of string for these events?

i.e. :contest_starting instead of 'contest_starting'.

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end++  def unsubscribe+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      Notification.find_each do |n|+        notif = UserNotification.find_by(user_id: user_notif.user_id, notification_id: n.id)

Misleading name? notif is of type UserNotification not Notification

nugriz

comment created time in a month

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 { 	"email_template": "Salam sejahtera,\n\n#{text}\n\nSalam,\nTim KTO Matematika",+	"email_template_with_unsubscribe_link": "Salam sejahtera,\n\n#{text}\n\nSalam,\nTim KTO Matematika\n\nAnda menerima email ini karena Anda subscribe ke notifikasi kontes kami. Klik link ini untuk berhenti menerima notifikasi jenis ini\n#{stop_this_notification_url}\nAtau Klik link ini untuk berhenti menerima email dari kami:\n #{unsubscribe_url}",

Please fix grammar / consistency

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end++  def unsubscribe+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      Notification.find_each do |n|+        notif = UserNotification.find_by(user_id: user_notif.user_id, notification_id: n.id)+        notif.destroy! if notif.present?+      end+    end+    flash.now[:alert] = 'Anda telah unsubscribe email KTOM'+  end++  def stop

Please come up with better names

nugriz

comment created time in a month

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 class UserNotification < ActiveRecord::Base   # Associations   belongs_to :user   belongs_to :notification++  def generate_token+    return token if token.present?++    user_notifications = UserNotification.where(user_id: user_id)++    if user_notifications.any? { |u_n| u_n.token.present? }

Why do you want the token to be the same across user notifications with the same user?

nugriz

comment created time in 18 days

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end++  def unsubscribe+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      Notification.find_each do |n|+        notif = UserNotification.find_by(user_id: user_notif.user_id, notification_id: n.id)+        notif.destroy! if notif.present?+      end+    end+    flash.now[:alert] = 'Anda telah unsubscribe email KTOM'+  end++  def stop+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      notif = UserNotification.find_by(+        user_id: user_notif.user_id, notification_id: params[:notification_id]+      )+      notif.destroy! if notif.present?+    end+    flash.now[:alert] = 'Anda telah mematikan notifikasi ini'
    flash.now[:alert] = 'Anda telah mematikan notifikasi ini.'
nugriz

comment created time in a month

Pull request review commentktomatematika/kontes-terbuka

Create draft pull request for [KT-15] Unsubscribe inactive people

 def delete     ).destroy!     render nothing: true   end++  def unsubscribe+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      Notification.find_each do |n|+        notif = UserNotification.find_by(user_id: user_notif.user_id, notification_id: n.id)+        notif.destroy! if notif.present?+      end+    end+    flash.now[:alert] = 'Anda telah unsubscribe email KTOM'+  end++  def stop+    user_notif = UserNotification.find_by(token: params[:token])+    if user_notif.present?+      notif = UserNotification.find_by(

This logic seems off, why don't you want to just use user_notif?

nugriz

comment created time in a month

PullRequestReviewEvent
PullRequestReviewEvent

issue closedmicrosoft/TypeScript

Catch variables typed as unknown is not correctly limited by type guards when used in functions

Bug Report

<!-- Please fill in each section completely. Thank you! -->

🔎 Search Terms

  • catch variables
  • unknown
  • type guards
  • functions

🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed. For npm: typescript@next This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies: --> This is a bug specific for version 4 onwards, when catch variables can be typed as unknown.

⏯ Playground Link

<!-- A link to a TypeScript Playground "Share" link which shows this behavior

The TypeScript Workbench can be used for more complex setups, try https://www.typescriptlang.org/dev/bug-workbench/

As a last resort, you can link to a repo, but these will be slower for us to investigate. --> https://www.typescriptlang.org/play?ts=4.4.2#code/C4JwngBA3gvhDGBDY8AWEAUBTAlNAUBBAJYBmmWJAdgM7CJXxYD25AoiCMyHlIUZjwBeAHwQsAOgC2WGjUQBzLAG5+MfDCA

💻 Code

<!-- Please post the relevant code sample here as well-->

try {} catch (e) {
  if (e instanceof Error) {
    () => e.message;
  }
}

In previous versions of TS that is >= 4:

try {} catch (e: unknown) {
  if (e instanceof Error) {
    () => e.message;
  }
}

🙁 Actual behavior

Does not work: it says e is of type unknown. I expected it to work because e has been type guarded.

🙂 Expected behavior

Should work, just like in the following example:

const fn = (a: string | Error) => {
  if (a instanceof Error) {
    () => a.message
  }
}

Workaround

Currently something like this works.

try {} catch (e) {
  if (e instanceof Error) {
    const message = e.message;
    () => message;
  }
}

closed time in a month

donjar

issue openedmicrosoft/TypeScript

Catch variables typed as unknown is not correctly limited by type guards when used in functions

Bug Report

<!-- Please fill in each section completely. Thank you! -->

🔎 Search Terms

  • catch variables
  • unknown
  • type guards
  • functions

🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed. For npm: typescript@next This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies: --> This is a bug specific for version 4 onwards, when catch variables can be typed as unknown.

⏯ Playground Link

<!-- A link to a TypeScript Playground "Share" link which shows this behavior

The TypeScript Workbench can be used for more complex setups, try https://www.typescriptlang.org/dev/bug-workbench/

As a last resort, you can link to a repo, but these will be slower for us to investigate. --> https://www.typescriptlang.org/play?ts=4.4.2#code/C4JwngBA3gvhDGBDY8AWEAUBTAlNAUBBAJYBmmWJAdgM7CJXxYD25AoiCMyHlIUZjwBeAHwQsAOgC2WGjUQBzLAG5+MfDCA

💻 Code

<!-- Please post the relevant code sample here as well-->

try {} catch (e) {
  if (e instanceof Error) {
    () => e.message;
  }
}

In previous versions of TS that is >= 4:

try {} catch (e: unknown) {
  if (e instanceof Error) {
    () => e.message;
  }
}

🙁 Actual behavior

Does not work: it says e is of type unknown. I expected it to work because e has been type guarded.

🙂 Expected behavior

Should work, just like in the following example:

const fn = (a: string | Error) => {
  if (a instanceof Error) {
    () => a.message
  }
}

Workaround

Currently something like this works.

try {} catch (e) {
  if (e instanceof Error) {
    const message = e.message;
    () => message;
  }
}

created time in a month