Skip to content

Instantly share code, notes, and snippets.

View bhaveshgohel's full-sized avatar
👨‍💻
I may be slow to respond.

Bhavesh Gohel bhaveshgohel

👨‍💻
I may be slow to respond.
View GitHub Profile
// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
console.error(err1);
callback(err1);
return;
}
f2(result1, (err2, result2) => {
@bhaveshgohel
bhaveshgohel / server.js
Created March 10, 2018 12:02 — forked from sadick254/server.js
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
@bhaveshgohel
bhaveshgohel / chat-server.js
Created March 10, 2018 12:01 — forked from graphicbeacon/chat-server.js
A simple TCP chat server with NodeJS, based on the example provided by creationix.
var net = require('net');
var sockets = [];
var port = 8000;
var guestId = 0;
var server = net.createServer(function(socket) {
// Increment
guestId++;
socket.nickname = "Guest" + guestId;
@bhaveshgohel
bhaveshgohel / zsh.md
Created February 15, 2018 10:23 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu
@bhaveshgohel
bhaveshgohel / OpenWithSublimeText3.bat
Created August 7, 2017 14:15 — forked from roundand/OpenWithSublimeText3.bat
Open folders and files with Sublime Text 3 from windows explorer context menu (tested in Windows 7)
@echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@bhaveshgohel
bhaveshgohel / handle_file_upload.php
Created June 3, 2016 09:50 — forked from ebidel/handle_file_upload.php
Uploading files using xhr.send(FormData) to PHP server
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
@bhaveshgohel
bhaveshgohel / ipow.c
Created March 15, 2016 05:43 — forked from orlp/ipow.c
int64_t ipow(int32_t base, uint8_t exp) {
static const uint8_t highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 255, // anything past 63 is a guaranteed overflow with base > 1
@bhaveshgohel
bhaveshgohel / app.js
Created November 28, 2015 11:45 — forked from krasu/app.js
Passport + Node.js / Automatic login after adding user
/**
* Module dependencies.
*/
var express = require('express')
, passport = require('passport')
, http = require('http')
, path = require('path')
, LocalStrategy = require('passport-local').Strategy;
@bhaveshgohel
bhaveshgohel / ftpserver.py
Created November 27, 2015 07:10 — forked from scturtle/ftpserver.py
simple ftp server by python
#!/usr/bin/env python2
# coding: utf-8
import os,socket,threading,time
#import traceback
allow_delete = False
local_ip = socket.gethostbyname(socket.gethostname())
local_port = 8888
currdir=os.path.abspath('.')
@bhaveshgohel
bhaveshgohel / SolarInfo.cs
Created October 30, 2015 10:46 — forked from cstrahan/SolarInfo.cs
A sunrise/sunset calculator.
using System;
using System.Diagnostics;
namespace SunriseCalculator
{
public class SolarInfo
{
public double SolarDeclination { get; private set; }
public TimeSpan EquationOfTime { get; private set; }
public DateTime Sunrise { get; private set; }