Skip to content

Instantly share code, notes, and snippets.

View benkoshy's full-sized avatar

Ben Koshy benkoshy

View GitHub Profile
@benkoshy
benkoshy / plane-line-intersection-autocad-dot-net.md
Created March 12, 2024 03:45
Intersection of Line with a plane - AutoCAD .net Code

Source: https://paulbourke.net/geometry/pointlineplane/

  • We could use native AutoCAD methods to further simplify - this is just a 'hello world' proof of concept.
        [CommandMethod("TestCoordinates2")]
        public void TestCoordinates2()
        {
            Point3d p0 = new Point3d(0, 2, 0); // plane points
            Point3d p1 = new Point3d(0, 2, 1); // plane points
@benkoshy
benkoshy / idea_api.md
Last active January 31, 2024 02:12
Pagy jsonapi considerations

The Old Way

class QuotesController < ApplicationController  

  def index   
    # assuming jsonapi extra is enabled
    @pagy, @quotes = pagy(Quote.all) 

    # this will fail if we are using a html pagy_nav helper
@benkoshy
benkoshy / debug-tekla-plugin-without-restarting.md
Created December 6, 2023 23:29
How to Debug a Tekla Plugin Without Restarting Visual Studio (Tekla Open API Tutorial)

Post build plugin in visual studio.

Watch out - change the version ID to suit your Tekla version!

set envDir=2022.0\Environments\common\extensions\TestWPFBeamPlugin

set pluginsDir=2022.0\nt\bin\plugins\TestWPFBeamPlugin

set tsDirA=D:\Program Files\Tekla Structures\
@benkoshy
benkoshy / ransack-post-form-pagy-2.md
Last active November 27, 2023 19:27
Pagy Documentation - Using Stimulus JS

Using Stimulus JS to POST

Whenever you use pagy links that require interception, you will need to reinitialise any javascript that you need to run. If you submit a form, and use a turbo frame to render those search results, and to also render the pagination links to those results, how are you going to reinitialize your javascript code to intercept those pagy page links?

Stimulus JS is very handy for reinitialising javascript code, and is useful if you are using a library like hotwire (by Basecamp) where changes are made to the DOM.

// pagy_controller.js - a stimulus JS controller
import { Controller } from "@hotwired/stimulus"
@benkoshy
benkoshy / port_forwarding.md
Last active November 14, 2023 06:58
How to enable a port forwarding script - with iptables
#!/bin/bash

echo 1 > /proc/sys/net/ipv4/ip_forward # must be enabled for the forwarding to work

iptables -F 
iptables -t nat -F  # flush the nat table
iptables -t mangle -F
iptables -X
@benkoshy
benkoshy / tekla-api-drawing-revision-no.md
Last active October 9, 2023 09:00
Get Revision Number of Drawings - Tekla Open API

The Tekla API is not very open - one of my peeves is that you cannot access a drawing's revision number, because it is not exposed. Not to worry, you can access it with a hack:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
@benkoshy
benkoshy / tekla-api-select-model-object-using-picker.md
Created October 2, 2023 02:22
Tekla - How to select an object in the model using a Tekla Picker

This is a console application.

You will need to install the approriate dlls from Tekla. This can now be down via a Nuget package:

We want to select a single object in the model using a picker. Here is some sample code. You can of course, configure this to select model objects if you wish.

using System;
using System.Collections.Generic;
@benkoshy
benkoshy / code-review-auto-complete.md
Created February 10, 2018 11:11
Code Review - AutoCompletion Problem
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/// <summary>
/// Here is the original coder review question
@benkoshy
benkoshy / NormansExtensionForDoubleClick.md
Created March 24, 2018 02:23
Norman's Extension Method but casts to Integer
public static class EditorSelectionExtension
    {
        public static PromptSelectionResult SelectAtPickBox(
            this Editor ed, Point3d pickBoxCentre)
        {
            //Get pick box's size on screen
            System.Windows.Point screenPt = ed.PointToScreen(pickBoxCentre, 1);

            //Get pickbox's size. Note, the number obtained from