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
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@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; }
@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 / 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 / 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 / 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 / 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 / zsh.md
Created February 15, 2018 10:23 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu