Skip to content

Instantly share code, notes, and snippets.

View kselax's full-sized avatar

Kselax kselax

View GitHub Profile
import io from 'socket.io-client'
import { bindActionCreators } from 'redux'
import store from '../redux/store'
import * as Actions from '../redux/actions.js'
const actions = bindActionCreators(Actions, store.dispatch)
const socket = io('http://localhost:3002')
@kselax
kselax / socketTodos.js
Created December 27, 2018 06:54
sockets
const { graphql } = require('graphql')
const s = require('../schema/todo')
module.exports = function(socket) {
const allTodosPag = query => {
graphql(s.schema, query, s.root)
.then(res => {
@kselax
kselax / todo.js
Created December 27, 2018 06:42
graphql schema file
const { buildSchema } = require('graphql')
const DB = require('../core/my_db/DB')
const schema = buildSchema(`
type Todo {
id: ID!
content: String!
completed: Boolean!
}
@kselax
kselax / DB.js
Created December 27, 2018 05:51
wraper for mysql
const mysql = require('mysql2')
class DB {
constructor() {
this.pool = null
}
setOptions(options) {
this.pool = mysql.createPool(options)
}
@kselax
kselax / todos.js
Created December 27, 2018 05:28
reducer of todo app
import { ADD_TODO,
TOGGLE_TODO,
SET_ALL_TODOS,
ADD_TODO_R,
DEL_TODO } from '../actionTypes.js'
const initialState = {
allIds: [],
byIds: {},
@kselax
kselax / db.js
Created December 13, 2018 00:32
DB class to work with the database
'use strict';
const fs = require('fs');
const Table = require('./Table');
const Log = require('../../model/Log');
class DB {
constructor() {
this.pool = null;
this.tablesNameArray = [];
@kselax
kselax / index.js
Created December 13, 2018 00:29
work with tables
'use strict';
const uuid = require('uuid');
function getJoin(joins, tableName) {
let output = '';
if (Array.isArray(joins)) {
joins.forEach((item) => {
output += `${item[0]} JOIN ${item[1]} ON ${tableName}.${item[2]} = ${item[1]}.${item[3]} `;
});
}
@kselax
kselax / index.js
Created December 12, 2018 04:14
check the existance a file or a directory
// check file or directory existance in async an sync way
const fs = require('fs')
// sync
if (fs.statSync(`${__dirname}/package.json`).isFile()) {
console.log('sync: file');
}
if (fs.statSync(`${__dirname}/.`).isDirectory()) {
console.log('sync: directory');
@kselax
kselax / exercise1.js
Last active December 8, 2018 17:40
chapter 6 of eloquent JavaScript
// A vector type
// Write a class Vec that represents a vector in two-dimensional space. It takes
// x and y parameters (numbers), which it should save to properties of the same
// name.
// Give the Vec prototype two methods, plus and minus , that take another
// vector as a parameter and return a new vector that has the sum or difference
// of the two vectors’ ( this and the parameter) x and y values.
// Add a getter property length to the prototype that computes the length of
// the vector—that is, the distance of the point (x, y) from the origin (0, 0).
@kselax
kselax / index.js
Created December 3, 2018 01:42
react + jquery
import React from 'react'
import './libs/jquery-ui-layout/jquery-ui-layout.css'
// import './css/style.css'
// import './css/style.css'
// import $ from './libs/jquery-v1.9.0.js'
class Chat extends React.Component {
constructor(props) {