Skip to content

Instantly share code, notes, and snippets.

View boyboi86's full-sized avatar
🙂
I may be slow to respond.

undefeated_ boyboi86

🙂
I may be slow to respond.
View GitHub Profile
@boyboi86
boyboi86 / create_synthetic_data.py
Last active February 28, 2024 08:36
Generate Synthetic High-Frequency Data for Quantitative research
import numpy as np
import pandas as pd
import datetime as dt
from sklearn.datasets import make_classification
def create_price_data(start_price: float = 1000.00, mu: float = .0, var: float = 1.0, n_samples: int = 1000000):
i = np.random.normal(mu, var, n_samples)
df0 = pd.date_range(periods=n_samples, freq=pd.tseries.offsets.Minute(), end=dt.datetime.today())
@boyboi86
boyboi86 / Yahoo_Finance_data_reader.py
Created May 19, 2020 04:21
This func draws data directly from yahoo finance. This requires pandas_datareader, only for simple resampling uses. Otherwise pls obtain proper data set.
import pandas as pd
import datetime as dt
import pandas_datareader.data as pdr
p = print
# =============================================================================
# return dataframe
# =============================================================================
@boyboi86
boyboi86 / SaveAsPDF.docx
Created July 23, 2017 13:19
MS word convert to PDF and save
Option Explicit
Sub AllSectionsToSubDoc()
Dim x As Long
Dim Sections As Long
Dim Doc As Document
Application.ScreenUpdating = False
Application.DisplayAlerts = False
@boyboi86
boyboi86 / GeoMap.service.js
Created December 21, 2016 07:25
Calculates great-circle distances between the two points – that is, the shortest distance over the earth’s surface – using the ‘Haversine’ formula.
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
@boyboi86
boyboi86 / ExampleModel.js
Created October 31, 2016 06:09 — forked from stephencoe/ExampleModel.js
Serve cached images from s3 instead of cloudinary. It needs tidying but it works and reduces bandwidth dramatically. - inspired by https://gist.github.com/dboskovic/23858511bf3c1cbebdbd
//...
Model.add({
content: {
type: Types.Html, wysiwyg: true, height: 400
},
hash : {
type : String,
hidden : true
},
@boyboi86
boyboi86 / router.node.js
Created October 29, 2016 10:51
NodeJS web server routes GET/POST
'use strict';
const http = require('http');
const url = require('url');
const qs = require('querystring');
const port = 3000;
/*Pure nodejs way of routing, an obj to provide methods as main key then routes with deep clone*/
let routes = {
@boyboi86
boyboi86 / auth.js
Created October 27, 2016 15:09
higher order component for react to secure routes
export default function (ComposedComponent) {
class Authentication extends Component{
/*Defined contextTypes to access context */
static contextTypes = {
router: React.PropTypes.object
}
/*Made used of context to define route*/
componentWillMount(){
@boyboi86
boyboi86 / EventEmitter.js
Created October 24, 2016 09:41
Building event emitter in ES6
class EventEmitter {
constructor(){
this.events = {};
}
on(eventName, cb){
if(this.events[eventName]){
this.events[eventName].push(cb);
} else {
this.events[eventName] = [cb];
}
@boyboi86
boyboi86 / html5-video-streamer.js
Created June 8, 2016 06:34 — forked from paolorossi/html5-video-streamer.js
Node.js HTML5 video streamer
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
*/
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = 'video.mp4';