Skip to content

Instantly share code, notes, and snippets.

View vinnyoodles's full-sized avatar
🏡
Working from home

Vincent Le vinnyoodles

🏡
Working from home
View GitHub Profile
@vinnyoodles
vinnyoodles / broadcast.js
Last active December 25, 2016 04:26
React Native Socket.io Broadcast Message
// Server side
socket.on('message', (message) => {
// Save the message document in the `messages` collection.
db.collection('messages').insert(message);
// The `broadcast` allows us to send to all users but the sender.
socket.broadcast.emit('message', message);
});
// Client side
@vinnyoodles
vinnyoodles / user.js
Created December 25, 2016 04:21
React Native Socket.io User
// Client side
determineUser() {
AsyncStorage.getItem('userId')
.then((userId) => {
if (userId) {
this.socket.emit('i-dont-need-an-id');
} else {
this.socket.emit('i-need-id');
this.socket.on('here-is-your-id', (id) => {
AsyncStorage.setItem('userId', id);
@vinnyoodles
vinnyoodles / client.js
Created December 25, 2016 03:44
React Native Socket.io Initial Client
import React from 'react';
import SocketIOClient from 'socket.io-client';
class Main extends React.Component {
constructor(props) {
super(props);
// Creating the socket-client instance will automatically connect to the server.
this.socket = SocketIOClient('http://localhost:3000');
}
@vinnyoodles
vinnyoodles / server.js
Last active December 25, 2016 03:44
React Native Socket.io Initial Server
var express = require('express');
var http = require('http')
var socketio = require('socket.io');
var app = express();
var server = http.Server(app);
var websocket = socketio(server);
server.listen(3000, () => console.log('listening on *:3000'));
// The event will be called when a client is connected.
import React from 'react';
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';
class Table extends React.Component {
constructor(props) {
super(props);
}
render() {
var products = [
{
@vinnyoodles
vinnyoodles / AppDelegate.swift
Last active June 20, 2016 16:14
DualSlideMenuViewController: refresh on action
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let defaults = NSUserDefaults.standardUserDefaults();
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
storyboard = UIStoryboard(name: "Main", bundle: nil)
let leftView = storyboard?.instantiateViewControllerWithIdentifier("LeftMenuController")
let rightView = storyboard?.instantiateViewControllerWithIdentifier("RightMenuController")