Friday, June 18, 2021

A Cheatsheet for Python Built-in Functions (Part 2: C-D)

 A Cheatsheet for Python Built-in Functions (Part 2: C-D)


# *** callable() ***
def func0():
    pass
print(callable(func0))  # Output: True
# *** chr() ***
print(chr(65))  # Output: A
# *** classmethod() ***
# Note: The new @classmethod decorator should be used instead of 
# the built-in function classmethod().
class MyClass1:
    myProperty = 1234
    def myFunc(self):
        print(self.myProperty)
obj0 = MyClass1()
obj0.myFunc()
MyClass1.myFunc = classmethod(MyClass1.myFunc)
MyClass1.myFunc() # myFunc is used as a class method (vs. instance method)
# *** compile() ***
myCode = '_a = 10 \n_b = 20 \nmySum = _a + _b \nprint("mySum =", mySum)'
myCodeObject = compile(myCode'myCodeString''exec')
exec(myCodeObject#  Output: 30
# *** complex() ***
print(complex(12))  # Output: (1+2j)
# *** delattr() ***
class MyClass2:
    myProperty1 = 1234
    myProperty2 = 'ABC'
myObj2 = MyClass2()
print(myObj2.myProperty2)
delattr(MyClass2'myProperty2')
#print(myObj2.myProperty2)  # Error: AttributeError: 'MyClass2' object has no attribute 'myProperty2' 
# *** dict() ***
myDic1 = dict(key1 = "val1"key2 = "val2"key3 = "val3")
print(myDic1)  # Output: {'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}
# *** dir() ***
class MyClass3:
    myProperty1 = 1234
    def myMethod1():
        pass
print(dir(MyClass3))  # Output:
"""
'__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', 
'__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', 
'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'myMethod1', 'myProperty1']
"""
# *** divmod() ***
print(divmod(73))  # Output: (2, 1)
# Note: The output is a tuple:
# divmod(dividend, divisor) => (quotient, reminder)


Wednesday, June 16, 2021

A Cheatsheet for Python Built-in Functions (Part 1: A-B)

A Cheatsheet for Python Built-in Functions (Part 1: A-B)

x1 = -1.5
x2 = 1.5
x3 = 255
b1 = x1 == x2
b2 = x1 == -x2
# *** abs() ***
print(abs(x1))  # Output: 1.5
# *** all() ***
print(all([not b1, b2]))  # Output: True
# *** any() ***
print(any([b1, b2]))  # Output: True
# *** ascii() ***
print(ascii("This is R in Farsi: ر"))  # Output: 'This is R in Farsi: \u0631'
print(ascii(set([b1, b2])))  # Output: {False, True}
# *** bin() ***
print(bin(x3))  # Output: 0b11111111
# *** bool() ***
print(bool(x3), bool(x2), bool(x1))  # Output: True True True
print(bool(0), bool(None), bool([]), bool(()), bool({})) # Output: False False False False False
# *** bytearray() ***
ba1 = bytearray([b1, b2])
print(ba1) # Output: bytearray(b'\x00\x01')
ba2 = bytearray("TEST"encoding='utf8')
print(ba2) # Output: bytearray(b'TEST')
ba3 = bytearray(8)
print(ba3) # Output: bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')
# *** bytes() ***
ba1 = bytes([b1, b2])
print(ba1) # Output: b'\x00\x01'
ba2 = bytes("TEST"encoding='utf8')
print(ba2) # Output: b'TEST'
ba3 = bytes(8)
print(ba3) # Output: '\x00\x00\x00\x00\x00\x00\x00\x00'




Declare Arrays in Python

Declare Arrays in Python

A Python List can be considered as a Dynamic Array. The following examples present how to declare an Array in Python.


arr1 = [0] * 8
print(arr1)
# Output: [0, 0, 0, 0, 0, 0, 0, 0]

arr2 = [""] * 8
print(arr2)
# Output: ['', '', '', '', '', '', '', '']

arr3 = [None] * 8
print(arr3)
# Output: [None, None, None, None, None, None, None, None]

arr4 = [None for i in range(08)]
print(arr4)
# Output: [None, None, None, None, None, None, None, None]



A Cheatsheet for Python Lists

A Cheatsheet for Python Lists 


# *** Creating a list ***
list1 = []
list2 = [1"item1"2.2]
list3 = [list1, list2, "a text"1234]
print(list3[1][1])
# Output:  item1
print(list3[-1]) # negative index are counted from the end.
# Output:  1234
# *** Length of a list ***
len3 = len(list3)
print(len3)
# Output:  4
# *** Appending new list items ***
for i in range(1014):
    list3.append(i)
list3.append([t for t in range(0103)])
print(list3)
# Output:  [[], [1, 'item1', 2.2], 'a text', 1234, 10, 11, 12, 13, [0, 3, 6, 9]]
print(list3[-1]) # negative index are counted from the end.
# Output:  [0, 3, 6, 9]
#
# Inserting new items into a list.
print(list2)
# Output:  [1, 'item1', 2.2]
list2.insert(2222)
print(list2)
# Output:  [1, 'item1', 222, 2.2]
#
# Extending a list.
list2.extend([t for t in range(0103)])
print(list2)
# Output:  [1, 'item1', 222, 2.2, 0, 3, 6, 9]
#
# Removing an items from a list.
list2.remove("item1")
print(list2)
# Output:  [1, 222, 2.2, 0, 3, 6, 9]
#
# Using pop method to get and remove an item.
val1 = list2.pop()
print(val1)
# Output:  9
val2 = list2.pop(2# index.
print(val2)
# Output:  2.2
#
# Slicing a list.
list4 = ["A""B""C""D""E""F""G"]
print(list4[:2])
# Output:  ['A', 'B']
print(list4[:-2])
# Output:  ['A', 'B', 'C', 'D', 'E']
print(list4[2:])
# Output:  ['C', 'D', 'E', 'F', 'G']
print(list4[2:4])
# Output:  ['C', 'D']
print(list4[::-1])
# Output:  [['G', 'F', 'E', 'D', 'C', 'B', 'A']

Thursday, December 31, 2020

Multiton

 

Multiton
Design Patterns
Creational Design Patterns



In computer programming, the Multiton Pattern is a design pattern which generalizes the singleton pattern in two different ways:
1) On copy of the corresponding Singleton for each data type,
2) On copy of the corresponding Singleton for each value of a parameter.
Where the Singleton Pattern permits only one instance of a class to be instantiated, the Multiton Pattern allows multiple instances of a class to be instantiated.



Functional Programming

Functional Programming is a computer programming paradigm in which the constituents of a computer program are functions. In the workflow of the program, you would find functions calling functions in a way that in one stack of calls you might observe tens or even hundreds of nested function calls. Functional Programming implementations make many complex algorithms be programmed easier than many other paradigms, however, its performance (speed of computer program executing) may be lower than those paradigms. 



Tuesday, May 7, 2019

GP :: Purchase Order Number

Purchase Order Number

SELECT PORDNMBR [Order ID], * FROM PM10000 WITH(nolock) WHERE DEX_ROW_TS > '2019-05-01';
SELECT PORDNMBR [Order ID], * FROM PM20000 WITH(nolock) WHERE DEX_ROW_TS > '2019-05-01';
SELECT PORDNMBR [Order ID], * FROM PM30200 WITH(nolock) WHERE DEX_ROW_TS > '2019-05-01';

Thursday, March 15, 2018

Best Bytes

        private static byte[] best = new byte[256]{
            0,  17,  34,  51,  68,  85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, // 00, 11, ... FF.
            1,  18,  35,  52,  69,  86, 103, 120, 137, 154, 171, 188, 205, 222, 239, 240, // 01, 12, ... F0.
           15,  16,  33,  50,  67,  84, 101, 118, 135, 152, 169, 186, 203, 220, 237, 254, // 0F, 10, ... FE.
            2,  19,  36,  53,  70,  87, 104, 121, 138, 155, 172, 189, 206, 223, 224, 241, // 02, 13, ... F1.
           14,  31,  32,  49,  66,  83, 100, 117, 134, 151, 168, 185, 202, 219, 236, 253, // 0E, 1F, ... FD.
            3,  20,  37,  54,  71,  88, 105, 122, 139, 156, 173, 190, 207, 208, 225, 242, // 03, 14, ... F2.
           13,  30,  47,  48,  65,  82,  99, 116, 133, 150, 167, 184, 201, 218, 235, 252, // 0D, 1E, ... FC.
            4,  21,  38,  55,  72,  89, 106, 123, 140, 157, 174, 191, 192, 209, 226, 243, // 04, 15, ... F3.
           12,  29,  46,  63,  64,  81,  98, 115, 132, 149, 166, 183, 200, 217, 234, 251, // 0C, 1D, ... FB.
            5,  22,  39,  56,  73,  90, 107, 124, 141, 158, 175, 176, 193, 210, 227, 244, // 05, 16, ... F4.
           11,  28,  45,  62,  79,  80,  97, 114, 131, 148, 165, 182, 199, 216, 233, 250, // 0B, 1C, ... FA.
            6,  23,  40,  57,  74,  91, 108, 125, 142, 159, 160, 177, 194, 211, 228, 245, // 06, 17, ... F5.
           10,  27,  44,  61,  78,  95,  96, 113, 130, 147, 164, 181, 198, 215, 232, 249, // 0A, 1B, ... F9.
            7,  24,  41,  58,  75,  92, 109, 126, 143, 144, 161, 178, 195, 212, 229, 246, // 07, 18, ... F6.
            9,  26,  43,  60,  77,  94, 111, 112, 129, 146, 163, 180, 197, 214, 231, 248, // 09, 1A, ... F8.
            8,  25,  42,  59,  76,  93, 110, 127, 128, 145, 162, 179, 196, 213, 230, 247  // 08, 19, ... F7.
        };

Thursday, March 1, 2018

GRREF::English::succinct

succinct

Python is a succinct language. Fortunately for you, that means this book doesn’t have pages and pages of cryptic code. [Ref: Machine Learning with TensorFlow By: Nishant Shukla, Publisher: Manning Publications, Pub. Date: February 2, 2018]





Copyright ©2018, GRREF, All rights reserved.
See Contents

Sunday, February 25, 2018

GRREF::SAB Heli Division

SAB Heli Division
Goblin-Helicopter :: SAB Heli Division

The company is focused on designing and building radio-controlled helicopter, Blade/Tail blades for RC Helicopter.

About SAB Heli Division
SAB HELI DIVISION is a Division of SAB, a company with 20 years of experience in designing and manufacturing carbon fiber rotor blades in Italy. SAB has been achieved worldwide success with numerous championships from World Cup Championship to European Championship, and other USA titles. SAB HELI DIVISION is a result of years of planning and designing the most modern helicopters at highest quality, most aggressive and an uncompromised passion for perfect helicopters. Goblin helicopters from SAB HELI DIVISION blur the tradition boundaries of what is possible to break into a new dimension of this hobby. The Goblin helicopters are very unique in design, ultra fast but also extremely robust for modern extreme 3D pilots. [source: http://www.goblin-helicopter.com/shop/about_us.php]

 


Copyright ©2018, GRREF, All rights reserved.
See Contents

Sunday, October 22, 2017

Best Piece of Advice by Elon Musk

The single best piece of advice: Constantly think about how you could be doing things better and questioning yourself.

Elon Musk

Thursday, October 19, 2017

Physics' Neural Networks

https://m.phys.org/news/2017-10-physics-boosts-artificial-intelligence-methods.html

Thursday, September 28, 2017

State Transitions Mapped into Directed Multigraph

State Transitions Mapped into Directed Multigraph

From: State of Starting 
To: State of Closed

State Transitions Mapped into Directed Graph
State Transitions Mapped into Directed Graph


S : States {}     Fact 1: States form a Directed Multigraph.
state S1 Example
state S2 Fact 2: Each State is a Node.
Fact 3: Each Transition is a Directed Member.
state Sh
|S|= h



State Transitions Mapped into Directed Multigraph
State Transitions Mapped into Directed Multigraph



Copyright ©2017, Software Developer, All rights reserved.
See Contents

Wednesday, September 27, 2017

Alpha Channel in Unity Game Engine

Alpha Channel in Unity Game Engine

Unity uses straight alpha blending. Hence, you need to expand the color layers. The alpha channel in Unity will be read from the first alpha channel in the Photoshop file (read more at source). 

Also see: Applying a Color to a Texture's Alpha Channel



***Rem)

For transparency, Unity can only support the alpha channel. Due to this, Unity provided an Action [AlphaUtility.zip as in the asset folder of this document, “2015 - SUMMARY-Unity3D-Part001.docx - Assets”] to be loaded into Photoshop. To understand this see Chapter 8 of http://www.digitaltutors.com/tutorial/603-Unity-Mobile-Game-Development-User-Interface-Design#overview.

Note: need to know masking to understand the last three lessons of http://www.digitaltutors.com/tutorial/603-Unity-Mobile-Game-Development-User-Interface-Design.
 


Copyright ©2017, Software Developer, All rights reserved.
See Contents

Saturday, August 12, 2017

Visual Studio 20XX's C# Language Specification

Visual Studio 20XX's C# Language Specification



Visual Studio 2012's C# Language Specification Version is 5.0.
You can download this spec from the Microsoft Developer Network (MSDN). If you've installed Visual Studio 2012, you can also find the spec on your computer in the Program Files (x86)/Microsoft Visual Studio 11.0/VC#/Specifications/1033 folder. However, installations of Visual Studio Express 2012 don't include this file.

The original Visual Studio 2015's C# Language Specification Version is 5.0 (Version 6.0 of the specification had not been approved as a standard at the time of releasing Visual Studio 2015.) The current [Aug 10, 2017] Visual Studio 2015's C# Language Specification Version is 6.0.
Visual Studio 2017's C# Language Specification Version is 7.0.



Copyright ©2017, Software Developer, All rights reserved.
See Contents

Monday, August 7, 2017

Introducing AADL and Its Tools

Introducing AADL and Its Tools

What is AADL?

The Architecture Analysis & Design Language, AADL, is designed for the specification, analysis, automated integration and code generation of real-time performance-critical (timing, safety, schedulability, fault tolerant, security, etc.) distributed computer systems. It provides a new vehicle to allow analysis of system designs (and system of systems) prior to development and supports a model-based, model-driven development approach throughout the system life cycle.



Ocarina

Ocarina is a stand-alone AADL model processor, written in Ada. It is distributed under the GPLv3 plus runtime exception.

It supports the following features:

• Parser: support both AADL1.0 and AADLv2 syntaxes;
• Code generation: targetting C real-time operating systems: RT-POSIX, Xenomai, RTEMS; and Ada using GNAT for native and Ravenscar targets;
• Model checking: mapping of AADL models onto Petri Nets, timed (TINA) or colored (CPN-AMI);
• Schedulability analysis: mapping of AADL models onto Cheddar or MAST models
• Model Analysis: using the REAL language, one can analyse an AADL model for particular patterns or compute metrics.
Ocarina is an independent tool, it can either be used
• Stand-alone: from the commande line
• OSATE2 Integration: Ocarina can also be integrated to OSATE2 using a dedicated plug-in, see the following page for more details.
• Library: Ocarina can be integrated in third-party tool, like Cheddar.

Ocarina runs on Linux, Windows, Mac OS X. Thanks to Ada portability, it can be ported to any platform supported by GNAT for native development.



AADL Tool: TASTE toolchain supported by the European Space Agency
 

 
AADL Tool: OSATE that includes a modeling platform, a graphical viewer and a constraint query languages


Code Generation with AADL: A State-of-the-Art Report

Their approach integrates two different modeling notations to capture system concerns:

1.The architecture is specified using AADL. This architecture defines the execution environment, software deployment, and configuration and includes the number of tasks, allocation to a processor, binding of a connection on a specific bus to transport data, and other specifications. Some people relate to this view as the so-called nonfunctional architecture (how the system provides its functions).

2.The behavior is specified using Simulink, which characterizes how the system processes and uses the data from its environment, for example, to compute new data or activate a device. Some relate to this view as the functional architecture (what functions the system provides).



Simulink

Simulink, developed by MathWorks, is a graphical programming environment for modeling, simulating and analyzing multidomain dynamic systems. Its primary interface is a graphical block diagramming tool and a customizable set of block libraries. It offers tight integration with the rest of the MATLAB environment and can either drive MATLAB or be scripted from it. Simulink is widely used in automatic control and digital signal processing for multidomain simulation and Model-Based Design.



Project P

The goal of Project P is to support the model-driven engineering of high-integrity embedded real-time systems by providing an open code generation framework able to: 1. Verify the semantic consistency of systems described using safe subsets of heterogeneous modeling languages, ranging from behavioural to architectural languages and presenting a synchronous and asynchronous semantics (Simulink/Matlab, Scicos, Xcos, SysML, MARTE, UML).
2.Generate optimized source code for multiple programming (Ada, C/C++) and syntesis (VHDL, SystemC) languages.
3. Support a multi-domain (avionics, space, and automotive) certification process by providing open qualification material.



Function Model

A function model or functional model in systems engineering and software engineering is a structured representation of the functions (activities, actions, processes, operations) within the modeled system or subject area.


Business Process Execution Language

The Web Services Business Process Execution Language (WS-BPEL), commonly known as BPEL (Business Process Execution Language), is an OASIS standard executable language for specifying actions within business processes with web services. Processes in BPEL export and import information by using web service interfaces exclusively.



AADL on IEEE Xplore
Google Search for AADL Code Generation
AADL Tutorials on YouTube


(LABEL) AADL Eclectics
(LABEL) Code Generation Eclectics




Copyright ©2017, Software Developer, All rights reserved.
See Contents

Mobile Game State Enum

Mobile Game State Enum

The following enumeration presents a comprehensive list of mobile game states [for App State enumeration refer to: App State Enum].
   
    NotSet
    LoadRequested
    Loading
    Loaded
    InitializationRequested
    Initializing
    Initialized
    StartRequested
    Starting
    Started
    Playing
    Idle
    NonFatalErrorEncountered
    FatalErrorEncountered
    PauseRequested
    Pausing
    Paused
    ResumeRequested
    Resuming
    Resumed
    CheckMiniGameStatus
    CheckSceneManagerStatus
    CheckLevelManagerStatus
    CheckUIDialogManagerStatus
    CheckAwardManagerStatus
    CheckGameStoreStatus
    CheckPlayerInventoryStatus
    CheckPartnerSearchStatus
    CheckPartnerStatus
    CheckOpponenttSearchStatus
    CheckOpponentStatus
    StopRequested
    Stopping
    Stopped
    CloseRequested
    Closing
    Closed
    UnloadRequested
    Unloading
    Unloaded
    Unknown
 



Stereotype: enum

Declaration :

    C++ : enum GameState
    Java : public enum GameState
    Php : public final class GameState
    Python : class GameState

    C# : public enum GameState

Logical Design (LABEL: Logical Design Eclectics)


Copyright ©2017, Software Developer, All rights reserved.
See Contents

App State Enum

App State Enum

The following enumeration presents a comprehensive list of mobile application states [for Mobile Game State enumeration refer to: Mobile Game State Enum].
   
    NotSet
    LoadRequested
    Loading
    Loaded
    InitializationRequested
    Initializing
    Initialized

    StartRequested
    Starting
    Started
    Running
    Idle
    SuspendRequested
    Suspending
    Suspended
    ReinstateRequested
    Reinstating
    Reinstated
    NonFatalErrorEncountered
    FatalErrorEncountered
    PauseRequested
    Pausing
    Paused
    ResumeRequested
    Resuming
    Resumed
    ExitRequested
    Exiting
    Exited
    StopRequested
    Stopping
    Stopped
    UnloadRequested
    Unloading
    Unloaded
    Unknown

 

Stereotype: enum

Declaration :

    C++ : enum AppState
    Java : public enum AppState
    Php : public final class AppState
    Python : class AppState

    C# : public enum AppState

Logical Design (LABEL: Logical Design Eclectics)


Copyright ©2017, Software Developer, All rights reserved.
See Contents

Wednesday, August 2, 2017

C# References

C# References
CSharp References

[1] Essential C# 6.0, By: Mark Michaelis; Eric Lippert, Publisher: Addison-Wesley Professional, Pub. Date: September 24, 2015, Print ISBN-13: 978-0-13-414104-6.


 

Copyright ©2017, Software Developer, All rights reserved.
See Contents

Friday, July 28, 2017

Types of Machine Learning Systems

Types of Machine Learning Systems

There are so many different types of Machine Learning systems that it is useful to classify them in broad categories based on [Ref. 2]:

    * Whether or not they are trained with human supervision (supervised, unsupervised, semi-supervised, and Reinforcement Learning)

    * Whether or not they can learn incrementally on the fly (online versus batch learning)

    * Whether they work by simply comparing new data points to known data points, or instead detect patterns in the training data and build a predictive model, much like scientists do (instance-based versus model-based learning)




Copyright ©2017, Software Developer, All rights reserved.
See Contents