Skip to content

Instantly share code, notes, and snippets.

View rjdscott's full-sized avatar

Rob Scott rjdscott

  • New York, New York
View GitHub Profile
@rjdscott
rjdscott / EvenSortVector.cpp
Created June 4, 2021 19:10
Sort a vector to have even integers first
int main(){
int t; cin>>t;
while (t--){
int n; cin>>n;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin>>v[i];
int next_even = 0;
int next_odd = n-1;
while (next_even < next_odd) {
if(v[next_even] % 2 == 0) next_even++;
@rjdscott
rjdscott / gcd.cpp
Created June 4, 2021 19:06
Greatest Common Denominator - C++
int gcd(int a, int b){
if(b==0) return a;
else return gcd(b, a%b);
}
@rjdscott
rjdscott / mod_ips_dividends.bas
Created September 3, 2018 01:01
Downloads dividend data from IRESS IPS
Option Explicit
' requires: IressServerSpiHelper, IressWorkbookCommon
' Function: Download security dividend history
Sub GetDividends()
Dim strMethodName As String, strExchange
Dim strStartDate As String, strEndDate As String
Dim dicTickers As Scripting.Dictionary
Dim i%, j%
Dim rngTickers
# dictionaries are key:value data stores
# keys must be unique, so no suplicates
# the basic structure looks like this
dict_basic = {
"key_1":"value_1",
"key_2":"value_2,
"key_n":"vlaue_n:
}
# dictionaries be nested, meaning a dictionary
@rjdscott
rjdscott / pandas-map-vs-replace.py
Created August 21, 2018 05:10
This gist shows how to create a new column in a DataFrame and compares the .map() vs .replace() function when replacing external values
import pandas as pd
# data to make the dataframe
data = {
'col1':['au','au','nz','USA'],
}
# dict to convert data from:to
dict_mapping = {
'au':'Australia',
import sqlite3
db_name = 'test.db'
with sqlite3.connection(db_name) as conn:
cur = conn.cursor()
sql = "select * from table"
data = cur.execute(sql)
for row in data:
@rjdscott
rjdscott / _vimrc
Created May 3, 2018 01:55
my vim config as of 2018-05-03
"vundle
set nocompatible
set title
filetype off
"behave mswin
" ================ General Config ====================
set number
set relativenumber
Option Explicit
Sub GetWeather()
Dim ws As Worksheet: Set ws = ActiveSheet
Dim req As New XMLHTTP
req.Open "GET", "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22Sydney%2C%20AU%22)%20and%20u%3D'c'&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", False
req.send
Dim objFileNode
Dim xmlNodeList
Option Explicit
Sub Mail_ActiveSheet()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim strFilePath As String
Dim strFilename As String
@rjdscott
rjdscott / RblpapiExample-Rs1.R
Last active October 9, 2017 05:38
This example downloads data from Bloomberg API and formats it for charting
#---------------------------------------------------------------
#
# Name: Rblpapi Historical Download Example
# Purpose: This code utilised the bloomberg API to download
# securities and returns for an index, and saves in
# csv for consumption later
#
# Author: RobScott
# date: Oct-2017
#