Skip to content

Instantly share code, notes, and snippets.

View phuochau's full-sized avatar
👨‍💻

Hau Vo phuochau

👨‍💻
View GitHub Profile
@phuochau
phuochau / UIHelper.js
Last active October 25, 2017 23:48
Better runAfterInteractions for React Native
import { InteractionManager } from 'react-native';
export const runAfterInteractions = (f) => {
let called = false;
const timeout = setTimeout(() => { called = true; f(); }, 500);
InteractionManager.runAfterInteractions(() => {
if (called) return;
clearTimeout(timeout);
f();
});
@phuochau
phuochau / config.yml
Last active September 24, 2017 13:01
CircleCI 2.0 configuration for Phoenix project
# Phoenix CircleCI 2.0 configuration file
#
# Modify configuration for Ecto in config/test.exs like below:
#
# config :project, Project.Repo,
# adapter: Ecto.Adapters.Postgres,
# username: System.get_env("DATA_DB_USER"),
# password: System.get_env("DATA_DB_PASS"),
# hostname: System.get_env("DATA_DB_HOST"),
# database: "project",
@phuochau
phuochau / absinthe_partitions_sample.ex
Last active October 19, 2017 22:47
Sample for using partitions (types, queries, mutations) in absinthe. It's very useful for big app or umbrella app.
# Types
defmodule Auth.GraphQL.Schema.Account do
use Absinthe.Schema.Notation
object :account do
field :id, :string
field :email, :string
field :password, :string
field :insert_at, :string
field :updated_at, :string
open -a Google\ Chrome --args --disable-web-security --user-data-dir
@phuochau
phuochau / absinthe_helper.ex
Last active October 25, 2017 23:51
Absinthe Helper for Elixir
defmodule Test.Support.AbsintheHelper do
def mutation_skeleton(query) do
%{
"operationName" => "",
"query" => "#{query}",
"variables" => ""
}
end
def query_skeleton(query, query_name) do
@phuochau
phuochau / test_helper.exs
Last active October 25, 2017 23:50
Load .ex module in unit testing in Elixir
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Sharing.Repo, :manual)
## load helpers, support
Code.load_file("test/case/ecto.ex")
Code.load_file("test/support/absinthe_helper.ex")
@phuochau
phuochau / sample_configuration.js
Last active March 26, 2018 17:46
Sample configuration for using Jest and vue-test-utils in nuxt.js project
// package.json
"jest": {
"roots": [
"<rootDir>/tests/unit"
],
"moduleNameMapper": {
"[\\s\\S]*.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tests/unit/__mocks__/fileMock.js",
"[\\s\\S]*.(css|less)$": "<rootDir>/tests/unit/__mocks__/styleMock.js",
"~/([a-zA-Z0-9/.\\-_]*)": "<rootDir>/src/$1"
@phuochau
phuochau / custom-schema-based-on-permission-absinthe_plug.ex
Last active October 8, 2024 09:54
Custom Plug for Absinthe with multiple schema based on permission
defmodule ApiWeb.GraphQL.Plug do
@moduledoc false
import Plug.Conn
alias ApiWeb.GraphQL.Schema
@guest_schema Absinthe.Plug.init schema: Schema.Guest
@admin_schema Absinthe.Plug.init schema: Schema.Admin
@user_schema Absinthe.Plug.init schema: Schema.User
def init(opts), do: opts
@phuochau
phuochau / README.md
Created October 23, 2017 13:04 — forked from bomberstudios/README.md
Loading a Cocoa Framework in a Sketch Plugin

This is what Craft does:

function loadFramework(pluginRoot) {
  if (NSClassFromString('PanelsManager') == null) {
    var mocha = [Mocha sharedRuntime];
    return [mocha loadFrameworkWithName:'Panels' inDirectory:pluginRoot];
  } else {
    return true;
 }
@phuochau
phuochau / callback_objc2cocoa.md
Last active April 11, 2018 23:40
Using callback from Objective-C to Cocoascript

Re-build cocoa framework

  • Clone source code from: https://github.com/ccgus/CocoaScript
  • Make MOJavascriptObject.h as public headers in Build Phases
  • Build project and we will get CocoaScript.framework
  • Copy CocoaScript.framework to your Xcode project

Define the objective-c methods with callback

API.h