Skip to content

Instantly share code, notes, and snippets.

View giautm's full-sized avatar
😍
Nice to meet you ʕ◔ϖ◔ʔ

Giau. Tran Minh giautm

😍
Nice to meet you ʕ◔ϖ◔ʔ
View GitHub Profile
@giautm
giautm / c
Last active December 23, 2017 05:12
Bug
import React from 'react';
import Link from 'next/link';
import { translate } from 'react-i18next';
import i18n from '../i18n';
import Frontend from '../components/frontend/Frontend/Frontend';
class Home extends React.Component {
render() {
return (
@giautm
giautm / App.js
Created February 6, 2018 08:25
Sketch App
import Expo from 'expo';
import * as ExpoPixi from 'expo-pixi';
import React, { Component } from 'react';
import { Image, StyleSheet, View } from 'react-native';
export default class App extends Component {
state = {
strokeColor: Math.random() * 0xffffff,
strokeWidth: Math.random() * 30 + 10,
};
package gormrepo
import (
"context"
"reflect"
"github.com/jinzhu/gorm"
eh "github.com/looplab/eventhorizon"
"github.com/pkg/errors"
import { defaultFieldResolver } from 'graphql';
import { SchemaDirectiveVisitor } from 'graphql-tools';
import { createError } from 'apollo-errors';
export const UserPerms = Symbol('Get User Permissions');
export const NotAuthorizedAll = createError('NotAuthorized', {
message: 'Not authorized, required ALL of the permissions',
});
directive @relayID(
type: String,
) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
type User {
id: ID! @relayID
email: String!
name: String!
}
@giautm
giautm / build-id.js
Created June 14, 2018 08:09
Next.JS Build-ID with last git commit
const fs = require('fs')
const path = require('path')
const { execFile } = require('child_process')
function lastCommitId(dir) {
return new Promise((resolve, reject) => {
const gitArgs = [
`--git-dir=${path.join(dir, '.git')}`,
`--work-tree=${dir}`,
'rev-parse',
import { vec2 } from 'gl-matrix';
const ZERO_VECTOR = vec2.create();
function linePerpendicularToLine(out, vec, middlePoint, weight) {
if (weight <= 0 || vec2.equals(vec, ZERO_VECTOR)) {
vec2.copy(out[0], middlePoint);
vec2.copy(out[1], middlePoint);
} else {
const perpendicular = vec2.fromValues(vec[1], -vec[0]);
@giautm
giautm / Firechat.js
Last active September 15, 2018 07:53
Real-time chat with firebase, support groups & direct chat.
import firebase from 'firebase'
export function defaultDirectKey(users) {
return users.sort().join('-')
}
class Firechat {
constructor(firebaseRef, options = {}) {
this.directKey = options.directKey || defaultDirectKey
this.maximumMessagesFetch = options.maximumMessagesFetch || 100
@giautm
giautm / phone-carriers.js
Created September 20, 2018 11:15
VN phone carriers detector
const MOBILE_REGEXP = /^(\+84|0)(3[2-9]|5[2689]|7[06-9]|8[1-5])[0-9]{7}$/
const PREFIX_CARRIERS = {
viettel: ["32","33","34","35","36","37","38","39"],
mobifone: ["70","79","77","76","78"],
vinaphone: ["83","84","85","81","82"],
vietnamobile: ["52","56","58"],
gmobile: ["59"]
};
function phoneCarrier(phone) {