Skip to content

Instantly share code, notes, and snippets.

🏄

Wayne Chu wayne5540

🏄
Block or report user

Report or block wayne5540

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wayne5540
wayne5540 / elixir.ex
Last active Nov 19, 2017
Ruby implementation for Elixir cond
View elixir.ex
defmodule Validator do
def validate_age(age) do
cond do
age < 18 -> "Under 18"
age < 21 -> "Under 21"
true -> "Adult"
end
end
end
View graph-3.md

# Building a GraphQL API in Rails - Part 3 - Best Practice

This is a series blog post cover above three topics of GraphQL:

  1. About GraphQL
  2. Building a basic API with Rails
  3. Some best practices

GraphQL is not a new thing, it already exist for a while, the reason I decide to investigate it is because Github released their GraphQL API alpha currently. We know Github has been a very good company for a long time, their RESTful API also becomes some kind of standard for developers, so it’s pretty interesting to see what’s new they’ve been released.

View graphql-2.md

Building a GraphQL API in Rails - Part 2 - Start Coding

This is a series blog post cover above three topics of GraphQL:

  1. About GraphQL
  2. Building a basic API with Rails
  3. Some best practices

GraphQL is not a new thing, it already exist for a while, the reason I decide to investigate it is because Github released their GraphQL API alpha currently. We know Github has been a very good company for a long time, their RESTful API also becomes some kind of standard for developers, so it’s pretty interesting to see what’s new they’ve been released.

View ViewController.swift
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
let contentController = WKUserContentController()
// Inject JavaScript which sending message to App
View ViewController.swift
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
let contentController = WKUserContentController()
let js: String = "var h1s = document.querySelectorAll('h1'); for (var i = 0; i < h1s.length; i++) { h1s[i].style.color = 'red' };"
@wayne5540
wayne5540 / ios-how-to-communicate-with-iframes.md
Last active May 18, 2019
This article is to show how to inject JavaScript into iframs under iOS web view and so we can communicate with it.
View ios-how-to-communicate-with-iframes.md

[iOS - Swift] How to communicate with iFrames inside WebView

To provide better shopping experience for Onefill users, we want to support as many shopping site as we can by injecting our JavaScript engine into those sites. However, some of them are using iframe which is outdated HTML tag to implement some forms like payment and signup. And due to security issue JavaScript can’t communicate with iframe unless it’s same domain or it’s your domain. So here is the approach we did to support iframe under iOS web view and so we can communicate with it.

  • Xcode: Version 8.2.1 (8C1002)
  • Swift: Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)

Conclusion first

View building-a-graphql-api-in-rails-part-1.md

Building a GraphQL API in Rails - Part 1

This is a series blog post cover above three topics of GraphQL:

  1. About GraphQL
  2. Building a basic API with Rails
  3. Some best practices

GraphQL is not a new thing, it already exist for a while, the reason I decide to investigate it is because Github released their GraphQL API alpha currently. We know Github has been a very good company for a long time, their RESTful API also becomes some kind of standard for developers, so it's pretty interesting to see what’s new they've been released.

View rails-json-schema-validation.md

Validate JSON schema in Rails

Topics

  1. What/Why JSON schema
  2. Apply to rails model validation
  3. Test your API endpoint with schema matcher
  4. Homework for a curious reader
  5. References
@wayne5540
wayne5540 / dump_db.md
Last active Apr 21, 2016
Postgre Dump DB
View dump_db.md

Dump DB Script, run under command line:
pg_dump -U postgres -Fc db_name > dbbackup.dump

Notes:

if zsh: command not found: pg_dump happened
add PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" to ~/.bash_profile

Resources:

You can’t perform that action at this time.