Skip to content

Instantly share code, notes, and snippets.

View sadick254's full-sized avatar
🎯
Focusing

Sadick sadick254

🎯
Focusing
View GitHub Profile
@sadick254
sadick254 / server.js
Last active March 10, 2018 12:02
A Simple TCP Chat Server In Node Js
//run this with 'node server.js' and then test in multiple computers using 'telnet 192.168.0.1 9000'
// replace '192.168.0.1' with your ip.
(function () {
'use strict';
let net = require('net');
let chatServer = net.createServer(),
clientList = []; // a list of connected clients/ machines
chatServer.on('connection', function (client) {
//once a client connects we add it to our clientList
@sadick254
sadick254 / mean.js
Created May 22, 2016 11:23
Calculating mean
function mean(obj)
{
var props = getProps(obj);
var means = [];
function findMean(item){
var found = -1;
for (var i = means.length - 1; i >= 0; i--) {
if(means[i].prop === item){
found = i;
}
package server
import (
"fmt"
"net"
)
type clients []net.Conn
// stores all the connected clients
var cls clients
@sadick254
sadick254 / actions.js
Last active November 1, 2017 12:36
minimizing vuex boilerplate
export const getUsers = ({commit}, params) => {
return axios.get('http://api.domain.com/users', {
params
}).then(resp => {
commit('GET_USERS_SUCCESS', resp.data)
return resp.data
})
}
export const getDrivers = ({commit}, params) => {
@sadick254
sadick254 / default_url.js
Last active November 1, 2017 12:40
minimizing vuex boilerplate
axios.defaults.baseURL = 'http://api.domain.com'
//then later in your actions
axios.get('/users') // to minimize typing the domain in full
// getDrivers
axios.get('/drivers')
export const get = ({commit}, {url = '', params = {}}) => {
axios.get(url, {
params
}).then(resp => {
return resp.data
})
}
export const get = ({commit}, {url = '', params = {}, type = '', canCommit = true}) => {
axios.get(url, {
params
}).then(resp => {
if (canCommit) {
commit(type, resp.data)
}
return resp.data
})
}
//get all shops
const shops = await this.$store.dispatch('get', {
url: '/shops',
params: {
type: 'all'
},
type: 'GET_SHOPS_SUCCESS'
})
// use your response if you need to
export default {
name: 'some-component',
data () {
return {
name: 'sadick'
}
},
methods: {
getUsername () {
this.$store.dispatch('getUsernameFromAPI')
/***********************************************************
* Some fancy comments here *
* *
***********************************************************/