Skip to content

Instantly share code, notes, and snippets.

View isc-rsingh's full-sized avatar

Raj Singh isc-rsingh

View GitHub Profile
@isc-rsingh
isc-rsingh / installzpm.cls
Created February 14, 2022 16:29
Script for InterSystems IRIS terminal. Useful if you don't have ZPM in your IRIS and can install with this one call in the terminal. Courtesy of @guillaume Rongier and @sergei Shutov and @Sergey Mikhailenko
set $namespace="%SYS" do ##class(Security.SSLConfigs).Create("ssl") set r=##class(%Net.HttpRequest).%New(),r.Server="pm.community.intersystems.com",r.SSLConfiguration="ssl" do r.Get("/packages/zpm/latest/installer"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c")
{
"datasets": [
{
"name": "The Museum of Modern Art (MoMA) Collection",
"url": "https://github.com/MuseumofModernArt/collection"
},
{
"name": "Coronavirus (Covid-19) Data in the United States",
"url": "https://github.com/nytimes/covid-19-data"
},
@isc-rsingh
isc-rsingh / cleanbostoncrimes.py
Last active May 2, 2021 03:34
Cleans up broken lines and unquoted strings in Boston crime incident data CSV files
# get the data from https://data.boston.gov/dataset/crime-incident-reports-august-2015-to-date-source-new-system
badfile = open('bostonpolice.csv', 'r')
betterfile = open('tmp.csv', 'w')
while True:
line = badfile.readline().strip()
if not line:
break
# figure out if the line has been broken incorrectly
@isc-rsingh
isc-rsingh / irisflask.py
Created October 7, 2020 14:10
Python Flask middleware app with InterSystems IRIS as the back end database
import pyodbc
from flask import Flask
from flask import request
from flask import render_template
import json
app = Flask(__name__)
connection = None
# default route
@app.route('/')
@isc-rsingh
isc-rsingh / pyodbc_iris_install.md
Created October 4, 2020 03:04
Get ODBC, PyODBC up and running for InterSystems IRIS

PyODBC installation instructions

Install ODBC

  • Windows: no installation necessary
  • Mac
    1. Run brew update
    2. Run brew install unixodbc
  • Linux
  1. Run apt-get update
@isc-rsingh
isc-rsingh / ConcatArrays.cls
Created May 4, 2020 14:00
Concatenate JSON arrays in ObjectScript
/// ObjectScript does not include any built-in method for appending one JSON dynamic array to another.
/// This is equivalent to the JavaScript concat() method.
/// Call it with any number of arguments to concatenate them into a new array.
/// If an argument is a dynamic array, its elements will be added. Otherwise the argument itself will be added.
/// Thanks to Pravin Barton in this article https://community.intersystems.com/post/code-sample-concatenate-json-arrays
ClassMethod ConcatArrays(pArgs...) As %DynamicArray
{
set outArray = ##class(%DynamicArray).%New() // or []
for i=1:1:pArgs {
set arg = pArgs(i)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
ROUTINE RightTriangle
/* compute area and hypotenuse of a right triangle
this routine contains examples of
new ObjectScript features */
Write !, "Compute the area and hypotenuse of a right triangle",
!, "given the lengths of its two sides."
Set units = "feet"
Set side1 = 3
Set side2 = 6
Do Compute( units, side1, side2)
@isc-rsingh
isc-rsingh / csv2objectscript.cls
Last active November 19, 2019 15:56
The simplest snippet to read from file in InterSystems Caché
set file = ##class(%File).%New( "data.csv" )
set sc = file.Open( "R" )
if $$$ISERR(sc) quit ; or do smth
while 'file.AtEnd {
set str=file.ReadLine()
for i=1:1:$length( str, ";" ) {
set id=$piece( str, ";" ,i )
write !, id // or do smth
}