Skip to content

Instantly share code, notes, and snippets.

View zapkub's full-sized avatar
🦄
Doing FINE !

Rungsikorn Rungsikavarnich zapkub

🦄
Doing FINE !
View GitHub Profile
// args
// questionId, selectedChoiceId
const question = await Question.findById(id);
// search if questionId is exist
if(question.answers.filter( answer => answer.questionId === questionId ).length === 0){
question.answers.push({ questionId, selectedChoiceId });
} else {
new Resolver({
resolve: async () => {
return new Promise((rs, rj) => {
Model.find({ _id }, function(err, result){
rs(result);
});
})
@zapkub
zapkub / batch-resizer.js
Last active April 16, 2017 10:05
node imagemagick batch resizing multithread
// Batch image resizing with Node Imagemagick
// author: Rungsikorn Rungsikavanich
// contact: rungsikorn@me.com
// Dependencies ( Need native imagemagick )
// $ brew install imagemagick
// $ npm i imagemagick lodash
// example: `$ DIR=../static/images/stock/herbarium-original node ./lib/batch-resizer.js`
// result image will be locate in ./resize folder
const im = require('imagemagick');
export type WorkPlace = {
id:string
viewCount:number
participant:{
male:number
female:number
ages:number[]
}
getAverageAges: ()=> number;
// @flow
import React from 'react';
import { Textfit } from 'react-textfit';
import _ from 'lodash';
import { TweenMax, Back, Power4 } from 'gsap';
import type { Song } from '../models';
import styles from './SongList.css';
export class PlayerSongList extends React.Component {
.container {
background: black;
display: flex;
flex-direction: column;
position: relative;
height: 100vh;
align-items: center;
justify-content: center;
box-sizing: border-box;
color: #f5f6f8;
graphqlExpress(req => {
const extendContext = require('./graphql').getGraphQLExtendedContext(req)
// }
return ({
schema,
tracing,
context: {
...req,
...extendContext
},
const rawSchema = {
typeDefs: `
type Query {
gqlTools: String
}
`,
resolvers: {
Query: {
gqlTools: () => 'Hi from gqlTools'
}
const momentTimeZone = require('moment-timezone');
function getBKKTime() {
const date = new Date()
const UTCDateString = date.toISOString()
const BKKDateString = moment.tz(UTCDateString, 'Asia/Bangkok').format()
return BKKDateString;
}
@zapkub
zapkub / apollo-ssr.jsx
Created October 24, 2017 07:42
apollo-with-ssr-user-session
import React from 'react'
import { ApolloProvider, getDataFromTree } from 'react-apollo'
import 'isomorphic-fetch'
import { sessionQuery } from './withSession'
import apolloClientFactory from '../../common/apolloClientFactory'
export default (Component) => class withData extends React.Component {
static async getInitialProps (context) {
if (typeof window === 'undefined') {
const props = {
user: context.req.user,