Skip to content

Instantly share code, notes, and snippets.

View AbDaniel's full-sized avatar

Abraham Daniel Immanul W AbDaniel

View GitHub Profile
@AbDaniel
AbDaniel / copilot-instructions.md
Created May 14, 2025 06:13 — forked from tonybaloney/copilot-instructions.md
Ant's pedantic Python Copilot instructions

Python Rules

  • Where possible, prefer duck-typing tests than isinstance, e.g. hasattr(x, attr) not isinstance(x, SpecificClass)
  • Use modern Python 3.9+ syntax
  • Prefer f-strings for formatting strings rather than .format or % formatting
  • When creating log statements, never use runtime string formatting. Use the extra argument and % placeholders in the log message
  • When generating union types, use the union operator, | , not the typing.Union type
  • When merging dictionaries, use the union operator
  • When writing type hints for standard generics like dict, list, tuple, use the PEP-585 spec, not typing.Dict, typing.List, etc.
  • Use type annotations in function and method signatures, unless the rest of the code base does not have type signatures
@AbDaniel
AbDaniel / path_to_key_value.json
Created June 17, 2024 17:28
JQ Example to list path to a key/value
{
"root" : {
"alpha" : [
{
"key1": "value1"
},
{
"key2": "value2"
}
],
@AbDaniel
AbDaniel / .block
Last active April 8, 2017 19:16 — forked from mbostock/.block
Bar Chart
license: gpl-3.0
import scipy.io.arff as arff
loaded_arff = arff.loadarff(open('../input/heart_train.arff', 'rb'))
(training_data, metadata) = loaded_arff
print(metadata['age']) #prints => ('numeric', None)
print(metadata['cp']) #prints => ('nominal', ('typ_angina', 'asympt', 'non_anginal', 'atyp_angina'))
print(metadata['sex']) #prints => ('nominal', ('female', 'male'))
//Method 1
def factorial1(n: Int, index: Int): Stream[Int] = {
n #:: factorial1(index * n, index + 1)
}
//Method 2
val factorial2: Stream[Int] = 1 #:: factorial2.zipWithIndex.map(x => x._1 * (x._2 + 1))
//Method 3
val factorial3: Stream[Int] = 1 #:: Stream.from(1).zip(factorial3).map(x => x._1 * x._2)