Blog

  • sublime-magma

    Magma (Sublime text package)

    Magma language support for Sublime Text 3. See also the MagmaSnippets package.

    This package provides syntax highlighting, comments, indentation rules and completions for the Magma language. Magma is a computer algebra system, homepage: http://magma.maths.usyd.edu.au/magma/.

    Installation

    Package Control (recommended)

    Install the Package Control package from https://packagecontrol.io, then use the Package Control: Install Package command to install the Magma package.

    Manually

    In Sublime click Preferences then Browse Packages..., then navigate to the User directory. Create a new directory there called Magma and copy the contents of this repository into it.

    Contributions and issues

    Please report any issues at https://github.com/chrisdoris/sublime-magma/issues.

    I welcome contributions/suggestions. Please get in touch via GitHub.

    License

    Copyright (C) 2018 Christopher Doris

    This is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this. If not, see http://www.gnu.org/licenses/.

    Visit original content creator repository
    https://github.com/cjdoris/sublime-magma

  • configure-ubuntu-host

    Desktop Configuration

    My dotfiles are scripts (mostly?).
    A few scripts to set up your new Ubuntu-based desktop installation.

    ToDo:

    • add some useful aliases
      • some have been added via configure_shell.zsh
    • proper dotfiles (~/.config) backup
    • set some firefox preferences
      • install extensions (ad block, bitwarden)
      • stop prompting to save passwords

    The scripts will install and configure the following:

    01_install-setup.sh

    • UFW (enable, default drop incoming, accept outgoing)
    • Installs some apt packages:
      • bat
      • gnome-tweaks
      • python3 python3-pip python3.10-venv
      • xclip
      • zsh
    • Installs some flatpak applications (more recent than apt versions):
      • foliate (ereader)
      • joplin (markdown editor, preview, notes sync, …)
    • Sets zsh as defualt user shell

    02_configure.zsh

    • Python3 supporting utilities:
      • pipx
      • poetry
    • Custom directories created (change or comment out as needed):
      • ~/Bin, ~/Projects

      # Create custom dirs
      CUSTOM_DIRS=(
      ~/Bin
      ~/Projects
      )
    • Installs VScodium (codium)
    • Intalls oh-my-zsh (install.sh runs directly via curl/download)
    • Installs MesloLGS nerd fonts for Powerlevel10K and rebuids font-cache
    • Installs Powerlevel10K config/theme for zsh
      (copied to ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/)

      • sets ZSH_THEME to Powerlevel10k, and restarts zsh

    These scripts are called from 02_configure.zsh

    • install_fonts_MesloLGS.zsh
    • install_vscodium.zsh

    Cmus script: cmus_config.zsh

    • installs the c music player cmus
    • Creates a playlist of all current SomaFM web radio channels
      (copied to ~/.config/cmus/playlists/soma_channels_http.pl)
    • Based on my somafm python script.

    Originally a gist

    References

    Visit original content creator repository
    https://github.com/CrustyBarnacle/configure-ubuntu-host

  • angular-unit-testing-helpers

    Build Status devDependency Status

    Angular Unit Testing Helpers

    Table of Contents

    Why?

    I’ve created this package to simplify unit testing in AngularJS apps. I had enough of writing repeated code. For every spec (controller, directive, service) I had to write the same injector and compile blocks of code, for every mocked service I had to write the same lines. With this package, everything becomes easier and faster.

    Features

    All selectors are using native Javascript querySelector or querySelectorAll, so jQuery is not requierd.

    Installation:

    1. Download package:
    npm install angular-unit-testing-helpers
    

    or

    bower install angular-unit-testing-helpers
    
    1. Inject it to karma.conf.js
    files: [
      'node_modules/angular-unit-testing-helpers/test-helpers.js',
      ...
    ],

    or

    files: [
      'bower_components/angular-unit-testing-helpers/test-helpers.js',
      ...
    ],
    1. Or import directly from package
    import { TestServ, TestElement } from 'angular-unit-testing-helpers';
    const TestServ = require('angular-unit-testing-helpers').TestServ;
    const TestElement = require('angular-unit-testing-helpers').TestElement;

    Back to top

    TypeScript:

    You can use this library with TypeScript. All you need to do:

    1. Have typings installed (1.x):
    npm install typings
    
    1. Have installed angular, angular-mocks and jquery typings
    typings install dt~jquery --save --global
    typings install dt~angular --save --global
    typings install dt~angular-mocks --save --global
    
    1. Have installed typings in angular-unit-testing-helpers
    typings install npm:angular-unit-testing-helpers
    

    Back to top

    TestServ documentation

    TestServ contructor:

    Without an argument:

    new TestServ()

    It will create an empty object;

    With an argument:

    new TestServ('$q');

    It will return real $q service;

    Implementation:

    window.TestServ = function(name) {
      var _this = this;
      if (!!name) {
        inject([name, function(service) {
          _this = service;
        }]);
        return _this;
      }
    };

    Back to top

    addMethod:

    var someService = new TestServ();
    someService.addMethod(name, returnedValue);

    addMethod will add an empty function to the someService at name value and also create spyOn on this created method. spyOn will return returnedValue. returnedValue can be undefined, a value, an object or a function. You can also construct chaining methods calls, for example:

    var someService = new TestServ();
    someService.addMethod('firstMethod').addMethod('secondMethod').addMethod('thirdMethod');

    More in examples.

    Implementation:

    addMethod: function(name, returnedValue) {
      if (typeof returnedValue === "function" ) {
        this[name] = returnedValue;
        spyOn(this, name).and.callThrough();
      } else {
        this[name] = angular.noop;
        spyOn(this, name).and.returnValue(returnedValue !== undefined ? returnedValue : this);
      }
      return this;
    }

    Back to top

    addPromise:

    var someService = new TestServ();
    someService.addPromise(name);

    addPromise will add an empty function to the someService at name value and also create spyOn on this created method. Same as addMethod. But spyOn will return object with then property, which will become a function. aThis function will bind two arguments to success and error property of someService[name]. So to call success promise you will simply call someService[name].success() and for failure promise someService[name].fail. You can also call this function with arguments (someService[name].success('someString')), so when you call this someService[name].then(function(response) { console.log(response)}), response will become ‘someString’`. You can also construct chaining methods calls, for example:

    var someService = new TestServ();
    someService.addMethod('firstMethod').addMethod('secondMethod').addPromise('promise');

    Implementation:

    addPromise: function(name) {
      var _this = this;
      _this[name] = function() {};
      spyOn(_this, name).and.returnValue({
        then: function(success, fail) {
          _this[name].success = success;
          _this[name].fail = fail;
        }
      });
      return this;
    }

    addProperty:

    var someService = new TestServ();
    someService.addProperty(name, returnedValue);

    addProperty will add a property to the someService with returnedValue as a value. You can also construct chaining methods calls, for example:

    var someService = new TestServ();
    someService.addProperty('someProperty', propertyValue).addProperty('someOtherProperty', otherPropertyValue);

    More in examples.

    Implementation:

    addProperty: function(name, returnedValue) {
      this[name] = returnedValue;
      return this;
    }

    get:

    var someService = new TestServ();
    someService.get(name);

    get will return property from a created service. You can use direct propery call (someService.name), this method is useful with typescript. More in typescript chapter.

    someService.get(name) === someService.name;

    Implementation:

    get: function(name) {
      return this[name];
    }

    Back to top

    TestServ examples

    TestServ examples

    TestElement documentation

    TestElement contructor:

    new TestElement();

    It will create an object, which will contain some angular services: $rootScope, $compile, $timeout, $controller, $templateCache;

    Implementation:

    window.TestElement = function() {
      var _this = this;
      inject(function($rootScope, $compile, $timeout, $controller, $templateCache, $filter) {
        _this._$scope = $rootScope.$new();
        _this.$originalScope = $rootScope.$new();
        _this.$compile = $compile;
        _this.$timeout = $timeout;
        _this.$controller = $controller;
        _this.$templateCache = $templateCache;
        _this.$filter = $filter;
      });
      this.name = '';
    };

    Back to top

    createCtrl:

    var element, someController, services = {
      someSrevice: mockedSomeService
    };
    element = new TestElement();
    someController = element.createCtrl(name, services);

    createCtrl will create and return a controller with ‘name’ and services object. You don’t need to inject $scope into services method, it’s injected by default if services.$scope doesn’t exists.

    Implementation:

    createCtrl: function(name, services) {
      if (!services) {
        services = {};
      }
      if (!services.$scope) {
        services.$scope = this._$scope;
      }
      this._ctrl = this.$controller(name, services);
      return this._ctrl;
    }

    Back to top

    addTemplate:

    var element;
    element = new TestElement();
    element.createCtrl(name);
    element.addTemplate(path, ctrlAs);

    addTemplate will create and return an angular element with current $scope. path is a path to the template that is stored in $templateCache. ctrlAs is an optional argument. If you are using controllerAs syntax, then ctrlAs should be the value of controllerAs property.

    Implementation:

    addTemplate: function(path, ctrlAs) {
      var template;
      template = this.$templateCache.get(path);
      this._el = angular.element(template);
    
      if (!!ctrlAs) {
        this._$scope[ctrlAs] = this._ctrl;
      }
    
      this.$compile(this._el)(this._$scope);
      this._$scope.$digest();
    
      try {
        this.$timeout.verifyNoPendingTasks();
      } catch (e) {
        this.$timeout.flush();
      }
    
      return this._el;
    }

    Back to top

    createDirective:

    var element;
    element = new TestElement();
    element.createDirective(name, html, scope);

    createDirective will create and return an angular element with with html and scope. name is a name of the directive, html is a string and scope is an object, e. g.: name = 'someDirective', html = '<some-directive attribute="someValue"></some-directive>'; scope = { someValue: 123 };.

    Implementation:

    createDirective: function(name, html, scope) {
      this.name = name;
      this._$scope = angular.extend(this.$originalScope, scope);
      this._el = this.$compile(elem)(this._$scope);
      this._$scope.$digest();
    
      try {
        this.$timeout.verifyNoPendingTasks();
      } catch (e) {
        this.$timeout.flush();
      }
      return this._el;
    }

    Back to top

    createComponent:

    var element;
    element = new TestElement();
    element.createComponent(name, html, scope);

    createComponent is an alias to createDirective method.

    Implementation:

    createComponent: function(name, html, scope) {
      this.createDirective(name, html, scope);
      return this._el;
    }

    Back to top

    createFilter:

    var filter;
    filter = new TestElement().createFilter(name);

    createFilter will return filter with given name.

    Implementation:

    createFilter: function(name) {
      return this.$filter(name);
    }

    Back to top

    get scope:

    element.scope

    scope will return current scope of the element.

    Implementation:

    get scope() {
      return this._ctrl ?
        this._$scope : Object.keys(this.dom.children()).length ?
          this.dom.children().scope() : this.dom.scope();
    }

    Back to top

    get ctrl:

    element.ctrl

    ctrl will return controller created with createCtrl method or controller created with createDirective method.

    Implementation:

    get ctrl() {
      return this._ctrl ? this._ctrl : angular.element(this._el).controller(this.name);
    }

    Back to top

    get dom:

    element.dom

    dom will return current angular element of the template created with addTemplate or the directive created with createDirective.

    Implementation:

    get dom() {
      return angular.element(this._el);
    }

    Back to top

    find:

    element.find(selector)

    find will return found angular element with selector.

    Implementation:

    find: function (selector) {
      return angular.element(this.dom[0].querySelector(selector));
    }

    Back to top

    findAll:

    element.findAll()

    findAll will return all found angular elements with selector as an array.

    Implementation:

    findAll: function (selector) {
      var htmlObject = this.dom[0].querySelectorAll(selector);
      var returnedArray = [];
      for (var property in htmlObject) {
        if (htmlObject.hasOwnProperty(property) && typeof htmlObject[property] !== 'number') {
          returnedArray.push(angular.element(htmlObject[property]));
        }
      }
      return returnedArray;
    }

    Back to top

    destroy:

    element.destroy()

    destroy will destroy current element.

    Implementation:

    destroy: function() {
      this._$scope.$destroy();
      this._el = null;
      this._ctrl = null;
    }

    Back to top

    clickOn:

    element.clickOn(selector);

    clickOn will click on element found with selector and make a $scope.$digest(). It returns a promise.

    Implementation:

    clickOn: function(selector) {
      if (this.dom[0].querySelector(selector)) {
        this.dom[0].querySelector(selector).click();
      } else {
        this.dom[0].click();
      }
      this._$scope.$digest();
      return this._getFlushedThenable();
    }

    Back to top

    inputOn:

    element.inputOn(selector, value, which);

    inputOn will set value of the element found with selector, trigger a input handler and make $scope.$digest(). It returns a promise. If you have many inputs with the same selector, then you can pass which input you want to react with by adding number as a third argument (0 is a first input). which is an optional argument.

    Implementation:

    inputOn: function(selector, value, which) {
      if (!which) {
        if (this.dom[0].querySelector(selector)) {
          angular.element(this.dom[0].querySelector(selector)).val(value).triggerHandler('input');
        } else if (this.dom[0].tagName == 'INPUT') {
          this._el.val(value).triggerHandler('input');
        }
      } else {
        if (this.dom[0].querySelectorAll(selector)[which]) {
          angular.element(this.dom[0].querySelectorAll(selector)[which]).val(value).triggerHandler('input');
        } else if (this.dom[0].tagName == 'INPUT') {
          this._el.val(value).triggerHandler('input');
        }
      }
      this._$scope.$digest();
      return this._getFlushedThenable();
    }

    Back to top

    TestElement examples

    TestElement examples

    Back to top

    TestModule documentation

    TestModule contructor:

    new TestModule(name);

    It will create an module object with given name;

    Implementation:

    window.TestModule = function(name) {
      this.module = angular.module(name);
      this.deps = this.module.value(name).requires;
    };

    Back to top

    hasModule:

    var someModule = new TestModule(moduleName);
    someModule.hasModule(dependencyModule);

    hasModule will return boolean value: true if moduleName has dependencyModule as a dependency and false if not.

    Implementation:

    hasModule: function(name) {
      return this.deps.indexOf(name) >= 0;
    }

    Back to top

    TestModule examples

    TestModule examples

    Back to top

    TestFactory documentation

    define:

    TestFactory.define(name, attributes);

    define will define a model with attributes for creating factories (it can be also a sequence). name should be unique. It should be called before any create action. The best solution is to define models in seperate folder and inject it at the beginning of the karma.config file (but after test-helpers).

    Example:

    TestFactory.define('user', {
      name: 'someName',
      id: 123,
      pet: {
        type: 'cat',
        name: 'Tom'
      },
      friends: ['Neo', 'Trinity', 'Morfeus']
    });

    Back to top

    create:

    TestFactory.create(name, attributes)

    create will create an object with model named name. attributes are an optional argument, it overwrites default attributes defined with define method.

    Example:

    user = TestFactory.create('user', {
      name: 'John',
      pet: {
        name: 'Jerry',
        type: 'mouse'
    });

    Back to top

    createList:

    TestFactory.createList(name, number, attributes)

    createList will create an collection of object with model named name. number defines how many objects in collections should be added. attributes are an optional argument, it overwrites default attributes defined with define method.

    Example:

    users = TestFactory.createList('user', 3, {
      name: 'John',
      pet: {
        name: 'Jerry',
        type: 'mouse'
    });

    Back to top

    defineSequence:

    TestFactory.defineSequence(name, argOne, argTwo)

    defineSequence will define a model with attributes for creating factories. name should be unique. It should be called before any sequence call. argOne can be iterator or function.

    Example:

    TestFactory.defineSequence('simpleSeq'); // => 1,2,3...
    TestFactory.defineSequence('seqWithIterator', 4); // => 4,8,12...
    TestFactory.defineSequence('seqWithFunction', function(value) {
      return 'Name ' + value;
    }); // => 'Name 1', 'Name 2', 'Name 3'...
    TestFactory.defineSequence('seqWithFunctionAndIterator', function(value) {
      return 'Age ' + value;
    }, 5); // => 'Age 5', 'Age 10', 'Age 15'...

    Back to top

    sequence:

    TestFactory.sequence(name);
    TestFactory.sequence(name);

    sequence returns a function. When you call it, then sequnce will increment. When you call clear method on it, then sequnce will be cleared to default value;

    Example:

    TestFactory.defineSequence('simpleSeq');
    TestFactory.sequence('simpleSeq')(); // => 1
    TestFactory.sequence('simpleSeq')(); // => 2
    TestFactory.sequence('simpleSeq').clear();
    TestFactory.sequence('simpleSeq')(); // => 1
    TestFactory.sequence('simpleSeq')(); // => 2

    Back to top

    TestFactory examples

    TestFactory examples

    TestDummy documentation

    filter:

    TestDummy.filter;

    filter will return the simpliest filter. It’s useful when filter is in another module.

    Implementation:

    get filter() {
      return function(input) {
        return input;
      };
    }

    Back to top

    directive:

    TestDummy.directive

    directive will return the simpliest directive. It’s useful when directive is in another module.

    Implementation:

    get directive() {
      return [{ restrict: 'AE' }];
    }

    Back to top

    TestDummy examples

    TestDummy examples

    Visit original content creator repository https://github.com/dakolech/angular-unit-testing-helpers
  • stats-base-dists-logistic-variance

    About stdlib…

    We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we’ve built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

    The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

    When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

    To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

    Variance

    NPM version Build Status Coverage Status

    Logistic distribution variance.

    The variance for a logistic random variable with location μ and scale s > 0 is

    $$\mathop{\mathrm{Var}}\left( X \right) = \tfrac{s^{2}\pi^{2}}{3}$$

    Installation

    npm install @stdlib/stats-base-dists-logistic-variance

    Alternatively,

    • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
    • If you are using Deno, visit the deno branch (see README for usage intructions).
    • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (see README).

    The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.

    To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.

    Usage

    var variance = require( '@stdlib/stats-base-dists-logistic-variance' );

    variance( mu, s )

    Returns the variance for a logistic distribution with location parameter mu and scale parameter s.

    var y = variance( 2.0, 1.0 );
    // returns ~3.29
    
    y = variance( 0.0, 1.0 );
    // returns ~3.29
    
    y = variance( -1.0, 4.0 );
    // returns ~52.638

    If provided NaN as any argument, the function returns NaN.

    var y = variance( NaN, 1.0 );
    // returns NaN
    
    y = variance( 0.0, NaN );
    // returns NaN

    If provided s <= 0, the function returns NaN.

    var y = variance( 0.0, 0.0 );
    // returns NaN
    
    y = variance( 0.0, -1.0 );
    // returns NaN

    Examples

    var randu = require( '@stdlib/random-base-randu' );
    var variance = require( '@stdlib/stats-base-dists-logistic-variance' );
    
    var mu;
    var s;
    var y;
    var i;
    
    for ( i = 0; i < 10; i++ ) {
        mu = ( randu()*10.0 ) - 5.0;
        s = randu() * 20.0;
        y = variance( mu, s );
        console.log( 'µ: %d, s: %d, Var(X;µ,s): %d', mu.toFixed( 4 ), s.toFixed( 4 ), y.toFixed( 4 ) );
    }

    C APIs

    Usage

    #include "stdlib/stats/base/dists/logistic/variance.h"

    stdlib_base_dists_logistic_variance( mu, s )

    Returns the variance for a logistic distribution with location mu and scale s.

    double out = stdlib_base_dists_logistic_variance( 0.0, 1.0 );
    // returns ~3.29

    The function accepts the following arguments:

    • mu: [in] double location parameter.
    • s: [in] double scale parameter.
    double stdlib_base_dists_logistic_variance( const double mu, const double s );

    Examples

    #include "stdlib/stats/base/dists/logistic/variance.h"
    #include <stdlib.h>
    #include <stdio.h>
    
    static double random_uniform( const double min, const double max ) {
        double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
        return min + ( v*(max-min) );
    }
    
    int main( void ) {
        double mu;
        double s;
        double y;
        int i;
    
        for ( i = 0; i < 25; i++ ) {
            mu = random_uniform( -5.0, 5.0 );
            s = random_uniform( 0.0, 20.0 );
            y = stdlib_base_dists_logistic_variance( mu, s );
            printf( "µ: %lf, s: %lf, Var(X;µ,s): %lf\n", mu, s, y );
        }
    }

    Notice

    This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

    For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

    Community

    Chat


    License

    See LICENSE.

    Copyright

    Copyright © 2016-2025. The Stdlib Authors.

    Visit original content creator repository https://github.com/stdlib-js/stats-base-dists-logistic-variance
  • MustAwaitAnalyzer

    MustAwaitAnalyzer

    CI

    Overview

    MustAwaitAnalyzer is a roslyn analyzer that enforces the use of await when calling methods that return:

    Install into Unity Project

    Requires Unity 2021.1.2f1 or later. You can add https://github.com/DeNA/MustAwaitAnalyzer.git?path=com.dena.must-await-analyzer#1.0.0 to Package Manager.

    Install into .NET Project

    You can install from NuGet packages.

    DENA008: Must use await

    Item Value
    Category DenaUnityAnalyzers
    Enabled True
    Severity Error
    CodeFix False

    Analysis Targets

    Examples are provided below:

    // bad
    namespace BadCase
    {
        public class Task1
        {
            Task Task_NoAsync() => Task.Run(() => {}); // DENA008, "Must use await" is reported
    
            public Task UseNoAsync()
            {
                Task_NoAsync(); // DENA008, "Must use await" is reported
            }
            
            Action<object> action = (object obj) => {};
        
            public async Task Hoge()
            {
                new Task(action, "a"); // DENA008, "Must use await" is reported
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class Task1
        {
            async Task Task_NoAsync() => await Task.Run(() => {}); // DENA008, "Must use await" is not reported
    
            public async Task UseNoAsync()
            {
                await Task_NoAsync(); // DENA008, "Must use await" is not reported
            }
            
            Action<object> action = (object obj) => {};
        
            public async Task Hoge()
            {
                await new Task(action, "a"); // DENA008, "Must use await" is not reported
            }
        }
    }

    NOTE1: The following types are not analyzed:

    NOTE2: If the last method in a method chain is named Terminate or Forget, the analysis does not take place.

    static async UniTask HogeAsync()
    {
        await Task.Run(() => {});
    }
    
    static void TerminateCase()
    {
        HogeAsync(); // DENA008 is reported due to missing await
        HogeAsync().GetAwaiter(); // DENA008 is reported due to missing await
        HogeAsync().GetAwaiter().Terminate(); // Nothing is reported
        HogeAsync().GetAwaiter().Forget(); // Nothing is reported
    }

    NOTE3: If a method call directly references a property that is an analysis target, the property reference is analyzed instead of the method call.

    // bad
    public async static Task<Task> BadPropertyCase()
    {
        var p = new Program();
        p.Example(); // DENA008 is reported
        return p.Example().Result; // Result returns Task, hence DENA008 is reported
    }
    
    public async Task<Task> Example()
    {
        return await new Task<Task>(null);
    }
    
    // good
    public async static Task<int> GoodPropertyCase()
    {
        var p = new Program();
        p.Example(); // DENA008 is reported
        return p.Example().Result; // Result returns int, hence DENA008 is not reported
    }
    
    public async Task<int> Example()
    {
        return await new Task<int>(null);
    }

    NOTE4: The following method calls, property references, and field references are excluded from analysis:

    • System.Threading.Tasks.Task.CompletedTask
    • System.Threading.Tasks.Task.FromResult
    • Cysharp.Threading.Tasks.UniTask.CompletedTask
    • Cysharp.Threading.Tasks.UniTask.FromResult

    NOTE5: If Task or UniTask objects are assigned to a variable and then awaited, no warning is issued. Additionally, if Task or UniTask objects are stored in a list (a class that implements System.Collections.Generic.IList) and awaited collectively, no warning is issued either.

    // good
    public async Task M1()
    {
        var task = Task.Run(() => {}); // DENA008 is not reported
        await task;
    }
    // good
    public async Task M1()
    {
        var list = new List<Task>();
        list.Add(Task.Run(() => {})); // DENA008 is not reported
        list.Add(Task.Run(() => {})); // DENA008 is not reported
        await Task.WhenAll(list);
    }

    Analysis Locations

    If the target of analysis exists within the following syntax and lacks an await, DENA008 will be reported.

    Within a Block

    // bad
    namespace BadCase
    {
        public class Task1
        {
            Task Task_NoAsync() => Task.Run(() => {}); // DENA008, "Must use await" is reported
    
            public Task UseNoAsync()
            {
                Task_NoAsync(); // DENA008, "Must use await" is reported
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class Task1
        {
            async Task Task_NoAsync() => await Task.Run(() => {});
    
            public async Task UseNoAsync()
            {
                await Task_NoAsync();
            }
        }
    }

    Within a Statement

    Examples for various statement types are shown below.

    • using Statement
    // bad
    
    namespace BadCase
    {
        public class Task1
        {
            public async void M1() 
            {
                using (M2()) // DENA008, "Must use await" is reported
                {
                }
            }
            
            public async Task<IDisposable> M2()
            {
                return await (Task<IDisposable>)Task.Run(() => {});
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class Task1
        {
            public async void M1() 
            {
                using (await M2()) // DENA008 is not reported
                {
                }
            }
            
            public async Task<IDisposable> M2()
            {
                return await (Task<IDisposable>)Task.Run(() => {});
            }
        }
    }
    • do-while Statement
    // bad
    public class BadCase {
        public async void M() 
        {
            do 
            {
                Task.Run(() => {}); // DENA008, "Must use await" is reported.
            }
            while (true);
            {
            }
        }
    }
    
    // good
    public class GoodCase {
        public async void M() 
        {
            do 
            {
                await Task.Run(() => {}); // DENA008 is not reported.
            }
            while (true);
            {
            }
        }
    }
    • if Statement
    // bad case
    namespace FailedCase
    {
        public class C {
            public async void M() 
            {
                if (M2()) // DENA008 is reported
                {
                }
            }
    
            public async Task<bool> M2()
            {
                return await (Task<bool>)Task.Run(() => {});
            }
        }
    }
    
    // good case
    namespace SuccessCase
    {
        public class C {
            public async void M() 
            {
                if (await M2())
                {
                }
            }
    
            public async Task<bool> M2()
            {
                return await (Task<bool>)Task.Run(() => {});
            }
        }
    }
    • yield Statement
    // bad
    namespace BadCase
    {
        public class YieldReturn
        {
            public async IAsyncEnumerable<int> M1()
            {
                for (int i = 0; i < 10; i++)
                {
                    yield return (Task<int>)Task.Run(() => 0); // DENA008 and CS0029 are reported
                }
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class YieldReturn
        {
            public async IAsyncEnumerable<int> M1()
            {
                for (int i = 0; i < 10; i++)
                {
                    yield return await (Task<int>)Task.Run(() => 0);
                }
            }
        }
    }

    Lambda

    // bad
    namespace FailedCase
    {
        public class Task1
        {
            Func<Task<int>> Example() => (() => Task.Run(() => 0)); // DENA008, "Must use await" is reported
    
            public void UseAsync()
            {
                Example(); // DENA008 is not reported since the return type is Func<Task<int>>, not Task<int>.
            }
        }
    }
    
    // good
    namespace SuccessCase
    {
        public class Task1
        {
            Func<Task<int>> Example() => (async () => await Task.Run(() => 0));
    
            public void UseAsync()
            {
                Example(); // DENA008 is not reported since the return type is Func<Task<int>>, not Task<int>.
            }
        }
    }

    Asynchronous Processing within Partial Methods

    namespace BadCase
    {
        interface IStudent
        {
            Task GetName();
        }
    
        partial class PartialMethod : IStudent
        {
            public virtual partial Task GetName();
        }
    
        public partial class PartialMethod
        {
            public virtual partial async Task GetName()
            {
                Task.Run(() => {}); // DENA008 is reported.
            }
        }
    }
    
    namespace GoodCase
    {
        interface IStudent
        {
            Task GetName();
        }
    
        partial class PartialMethod : IStudent
        {
            public virtual partial Task GetName();
        }
    
        public partial class PartialMethod
        {
            public virtual partial async Task GetName()
            {
                await Task.Run(() => {}); // DENA008, "Must use await" is not reported
            }
        }
    }

    Target-typed Inference

    // badcase
    namespace BadCase
    {
        public class TargetTypedNewExpression
        {
            Func<object, int> func = null;
    
            public async Task<int> Hoge()
            {
                return await new Task<int>(func, "a");
            }
    
            public async void M()
            {
                Dictionary<string, int> field = new()
                {
                    { "item1", Hoge() } // DENA008 is reported
                };
            }
        }
    }
    
    // GoodCase
    namespace GoodCase
    {
        public class TargetTypedNewExpression
        {
            Func<object, int> func = null;
    
            public async Task<int> Hoge()
            {
                return await new Task<int>(func, "a");
            }
    
            public async void M()
            {
                Dictionary<string, int> field = new()
                {
                    { "item1", await Hoge() } // DENA008, "Must use await" is not reported
                };
            }
        }
    }
    Visit original content creator repository https://github.com/DeNA/MustAwaitAnalyzer
  • MustAwaitAnalyzer

    MustAwaitAnalyzer

    CI

    Overview

    MustAwaitAnalyzer is a roslyn analyzer that enforces the use of await when calling methods that return:

    Install into Unity Project

    Requires Unity 2021.1.2f1 or later. You can add https://github.com/DeNA/MustAwaitAnalyzer.git?path=com.dena.must-await-analyzer#1.0.0 to Package Manager.

    Install into .NET Project

    You can install from NuGet packages.

    DENA008: Must use await

    Item Value
    Category DenaUnityAnalyzers
    Enabled True
    Severity Error
    CodeFix False

    Analysis Targets

    Examples are provided below:

    // bad
    namespace BadCase
    {
        public class Task1
        {
            Task Task_NoAsync() => Task.Run(() => {}); // DENA008, "Must use await" is reported
    
            public Task UseNoAsync()
            {
                Task_NoAsync(); // DENA008, "Must use await" is reported
            }
            
            Action<object> action = (object obj) => {};
        
            public async Task Hoge()
            {
                new Task(action, "a"); // DENA008, "Must use await" is reported
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class Task1
        {
            async Task Task_NoAsync() => await Task.Run(() => {}); // DENA008, "Must use await" is not reported
    
            public async Task UseNoAsync()
            {
                await Task_NoAsync(); // DENA008, "Must use await" is not reported
            }
            
            Action<object> action = (object obj) => {};
        
            public async Task Hoge()
            {
                await new Task(action, "a"); // DENA008, "Must use await" is not reported
            }
        }
    }

    NOTE1: The following types are not analyzed:

    NOTE2: If the last method in a method chain is named Terminate or Forget, the analysis does not take place.

    static async UniTask HogeAsync()
    {
        await Task.Run(() => {});
    }
    
    static void TerminateCase()
    {
        HogeAsync(); // DENA008 is reported due to missing await
        HogeAsync().GetAwaiter(); // DENA008 is reported due to missing await
        HogeAsync().GetAwaiter().Terminate(); // Nothing is reported
        HogeAsync().GetAwaiter().Forget(); // Nothing is reported
    }

    NOTE3: If a method call directly references a property that is an analysis target, the property reference is analyzed instead of the method call.

    // bad
    public async static Task<Task> BadPropertyCase()
    {
        var p = new Program();
        p.Example(); // DENA008 is reported
        return p.Example().Result; // Result returns Task, hence DENA008 is reported
    }
    
    public async Task<Task> Example()
    {
        return await new Task<Task>(null);
    }
    
    // good
    public async static Task<int> GoodPropertyCase()
    {
        var p = new Program();
        p.Example(); // DENA008 is reported
        return p.Example().Result; // Result returns int, hence DENA008 is not reported
    }
    
    public async Task<int> Example()
    {
        return await new Task<int>(null);
    }

    NOTE4: The following method calls, property references, and field references are excluded from analysis:

    • System.Threading.Tasks.Task.CompletedTask
    • System.Threading.Tasks.Task.FromResult
    • Cysharp.Threading.Tasks.UniTask.CompletedTask
    • Cysharp.Threading.Tasks.UniTask.FromResult

    NOTE5: If Task or UniTask objects are assigned to a variable and then awaited, no warning is issued. Additionally, if Task or UniTask objects are stored in a list (a class that implements System.Collections.Generic.IList) and awaited collectively, no warning is issued either.

    // good
    public async Task M1()
    {
        var task = Task.Run(() => {}); // DENA008 is not reported
        await task;
    }
    // good
    public async Task M1()
    {
        var list = new List<Task>();
        list.Add(Task.Run(() => {})); // DENA008 is not reported
        list.Add(Task.Run(() => {})); // DENA008 is not reported
        await Task.WhenAll(list);
    }

    Analysis Locations

    If the target of analysis exists within the following syntax and lacks an await, DENA008 will be reported.

    Within a Block

    // bad
    namespace BadCase
    {
        public class Task1
        {
            Task Task_NoAsync() => Task.Run(() => {}); // DENA008, "Must use await" is reported
    
            public Task UseNoAsync()
            {
                Task_NoAsync(); // DENA008, "Must use await" is reported
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class Task1
        {
            async Task Task_NoAsync() => await Task.Run(() => {});
    
            public async Task UseNoAsync()
            {
                await Task_NoAsync();
            }
        }
    }

    Within a Statement

    Examples for various statement types are shown below.

    • using Statement
    // bad
    
    namespace BadCase
    {
        public class Task1
        {
            public async void M1() 
            {
                using (M2()) // DENA008, "Must use await" is reported
                {
                }
            }
            
            public async Task<IDisposable> M2()
            {
                return await (Task<IDisposable>)Task.Run(() => {});
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class Task1
        {
            public async void M1() 
            {
                using (await M2()) // DENA008 is not reported
                {
                }
            }
            
            public async Task<IDisposable> M2()
            {
                return await (Task<IDisposable>)Task.Run(() => {});
            }
        }
    }
    • do-while Statement
    // bad
    public class BadCase {
        public async void M() 
        {
            do 
            {
                Task.Run(() => {}); // DENA008, "Must use await" is reported.
            }
            while (true);
            {
            }
        }
    }
    
    // good
    public class GoodCase {
        public async void M() 
        {
            do 
            {
                await Task.Run(() => {}); // DENA008 is not reported.
            }
            while (true);
            {
            }
        }
    }
    • if Statement
    // bad case
    namespace FailedCase
    {
        public class C {
            public async void M() 
            {
                if (M2()) // DENA008 is reported
                {
                }
            }
    
            public async Task<bool> M2()
            {
                return await (Task<bool>)Task.Run(() => {});
            }
        }
    }
    
    // good case
    namespace SuccessCase
    {
        public class C {
            public async void M() 
            {
                if (await M2())
                {
                }
            }
    
            public async Task<bool> M2()
            {
                return await (Task<bool>)Task.Run(() => {});
            }
        }
    }
    • yield Statement
    // bad
    namespace BadCase
    {
        public class YieldReturn
        {
            public async IAsyncEnumerable<int> M1()
            {
                for (int i = 0; i < 10; i++)
                {
                    yield return (Task<int>)Task.Run(() => 0); // DENA008 and CS0029 are reported
                }
            }
        }
    }
    
    // good
    namespace GoodCase
    {
        public class YieldReturn
        {
            public async IAsyncEnumerable<int> M1()
            {
                for (int i = 0; i < 10; i++)
                {
                    yield return await (Task<int>)Task.Run(() => 0);
                }
            }
        }
    }

    Lambda

    // bad
    namespace FailedCase
    {
        public class Task1
        {
            Func<Task<int>> Example() => (() => Task.Run(() => 0)); // DENA008, "Must use await" is reported
    
            public void UseAsync()
            {
                Example(); // DENA008 is not reported since the return type is Func<Task<int>>, not Task<int>.
            }
        }
    }
    
    // good
    namespace SuccessCase
    {
        public class Task1
        {
            Func<Task<int>> Example() => (async () => await Task.Run(() => 0));
    
            public void UseAsync()
            {
                Example(); // DENA008 is not reported since the return type is Func<Task<int>>, not Task<int>.
            }
        }
    }

    Asynchronous Processing within Partial Methods

    namespace BadCase
    {
        interface IStudent
        {
            Task GetName();
        }
    
        partial class PartialMethod : IStudent
        {
            public virtual partial Task GetName();
        }
    
        public partial class PartialMethod
        {
            public virtual partial async Task GetName()
            {
                Task.Run(() => {}); // DENA008 is reported.
            }
        }
    }
    
    namespace GoodCase
    {
        interface IStudent
        {
            Task GetName();
        }
    
        partial class PartialMethod : IStudent
        {
            public virtual partial Task GetName();
        }
    
        public partial class PartialMethod
        {
            public virtual partial async Task GetName()
            {
                await Task.Run(() => {}); // DENA008, "Must use await" is not reported
            }
        }
    }

    Target-typed Inference

    // badcase
    namespace BadCase
    {
        public class TargetTypedNewExpression
        {
            Func<object, int> func = null;
    
            public async Task<int> Hoge()
            {
                return await new Task<int>(func, "a");
            }
    
            public async void M()
            {
                Dictionary<string, int> field = new()
                {
                    { "item1", Hoge() } // DENA008 is reported
                };
            }
        }
    }
    
    // GoodCase
    namespace GoodCase
    {
        public class TargetTypedNewExpression
        {
            Func<object, int> func = null;
    
            public async Task<int> Hoge()
            {
                return await new Task<int>(func, "a");
            }
    
            public async void M()
            {
                Dictionary<string, int> field = new()
                {
                    { "item1", await Hoge() } // DENA008, "Must use await" is not reported
                };
            }
        }
    }
    Visit original content creator repository https://github.com/DeNA/MustAwaitAnalyzer
  • discord-applemusic-rich-presence

    Discord’s Rich Presence from Apple Music

    This is a simple binary that uses Apple Script to grab the current song being played on Apple Music, and reports it as Discord Rich Presence.

    You can leave it running “forever”, and it should work in a loop.

    Install

    To use it, simply install it with:

    brew install caarlos0/tap/discord-applemusic-rich-presence

    Run

    And then start and enable the service with:

    brew services start caarlos0/tap/discord-applemusic-rich-presence

    And that should do the trick 😃

    F.A.Q.

    How it looks like?

    It looks more or less like this:

    Screenshot

    Can it look more like the Spotify integration?

    No. Nothing I can do, AFAIK, it’s a Discord limitation.

    Clicking in “Search in Apple Music” does not work…

    Apparently… you can’t click in buttons in your own Rich Presence. Ask a friend to click on yours to see if it is really not working.

    Nothing happens…

    Sometimes you’d need to restart the service and/or Discord. No idea why, haven’t catch a single error about it, it just stops working.

    To restart:

    brew services restart caarlos0/tap/discord-applemusic-rich-presence

    Where are the logs?

    tail -f $(brew --prefix)/var/log/discord-applemusic-rich-presence.log

    Hat tip to:

    And many other projects that do the same thing.

    Visit original content creator repository https://github.com/caarlos0/discord-applemusic-rich-presence
  • MSK-diffusion-MRI

    From the channel: https://www.youtube.com/@jmriismrm5389

    Cyril Tous – Characterizing Myoarchitecture of the Supraspinatus / Infraspinatus With MRI DTI :

    https://www.youtube.com/watch?v=2LvwYVPjPp0

    TITLE: Characterizing the Myoarchitecture of the Supraspinatus and Infraspinatus Muscles With MRI Using Diffusion Tensor Imaging

    ABSTRACT:
    Background: The societal cost of shoulder disabilities in our aging society keeps rising. Providing biomarkers of early changes in the microstructure of rotator cuff (RC) muscles might improve surgical planning. Elevation angle (E1A) and pennation angle (PA) assessed by ultrasound change with RC tears. Furthermore, ultrasounds lack repeatability.

    Purpose: To propose a repeatable framework to quantify the myocyte angulation in RC muscles.

    Study type: Prospective.

    Subjects: Six asymptomatic healthy volunteers (1 female aged 30 years; 5 males, mean age 35 years, range 25-49 years), who underwent three repositioned scanning sessions (10 minutes apart) of the right infraspinatus muscle (ISPM) and supraspinatus muscle (SSPM).

    Field strength/sequence: 3-T, T1-weighted and diffusion tensor imaging (DTI; 12 gradient encoding directions, b-values of 500 and 800 s/mm2 ).

    Assessment: Each voxel was binned in percentage of depth defined by the shortest distance in the antero-posterior direction (manual delineation), i.e. the radial axis. A second order polynomial fit for PA across the muscle depth was used, while E1A described a sigmoid across depth:E1Asig=E
    1Arange × sigmf(1:100% depth,(−EA1grad,E1Aasym))+E1Ashift.

    Statistical tests: Repeatability was assessed with the nonparametric Wilcoxon’s rank-sum test for paired comparisons across repeated scans in each volunteer for each anatomical muscle region and across repeated measures of the radial axis. A P-value Ë‚0.05 was considered statistically significant.

    Results: In the ISPM, E1A was constantly negative, became helicoidal, then mainly positive across the antero-posterior depth, respective at the caudal, central and cranial regions. In the SSPM, posterior myocytes ran more parallel to the intramuscular tendon (PA≈0°), while anterior myocytes inserted with a pennation angle (PA≈−20°). E1A and PA were repeatable in each volunteer (error ˂ 10%). Intra-repeatability of the radial axis was achieved (error ˂ 5%).

    Data conclusion: ElA and PA in the proposed framework of the ISPM and SSPM are repeatable with DTI. Variations of myocyte angulation in the ISPM and SSPM can be quantified across volunteers.

    Evidence level: 2 TECHNICAL EFFICACY: Stage 2.

    Keywords: angle; diffusion tensor imaging; elevation; pennation; rotator cuff tears; tractography.

    © 2023 The Authors. Journal of Magnetic Resonance Imaging published by Wiley Periodicals LLC on behalf of International Society for Magnetic Resonance in Medicine.


    (https://onlinelibrary.wiley.com/doi/10.1002/jmri.28840)

    Visit original content creator repository
    https://github.com/c-tous/MSK-diffusion-MRI

  • radar-cleaning

    RADAR Cleaning

    R cleaning scripts used for network data from Northwestern University’s RADAR Project. The primary purpose of this repository is to provide version control for a body of scripts that have previously been managed with filename changes. However, some additional information and context is provided for both potential users of the scripts and individuals curious about the scripts used for this data.

    Prerequisites

    • R
    • Neo4j (select scripts)

    Getting started

    • Clone this repository to your machine by running git clone <repo-url>.

    • If you are involved in the RADAR Project, please request access to the network data, which will give you access to configure_networkscripts.txt, REDCapIDs.txt, and corrections.json.

    • If you want to run all three of the core cleaning scripts, run Process_NetworkFiles.R.

    • If you want to run an individual processing script, you can find them in the Process/ directory.

    • If you want to run any number of the miscellaneous scripts (data pulls, reports, etc.), you can do this by running Misc_NetworkScripts.R.

    • If you want to run an individual ‘miscellaneous’ script, you can find them in the Misc/ directory.

    Notes

    Clean_NetworkFiles.R

    Data corrections are stored in JSON format. You can review the command line interface used to generate this JSON file at https://github.com/mchlltt/inquirer-corrections.

    REDCapIDPull.js

    This file is the code for a bookmarklet pulls survey dates and participant IDs from REDCap (Research Electronic Data Capture). If you have access to RADAR Survey data in REDCap, you can use this script by taking the following steps.

    • Create a new bookmark in your browser.
    • Set the title of the bookmark to ‘REDCap ID Pull’ or something else that you will understand.
    • Copy the text in REDCapIDPull.js.
    • Paste the contents of REDCapIDPull.js into the URL field of the new bookmark.
    • Click this bookmark when you are on the RADAR Survey/Demographics page.
    • Open your browser’s developer tools. In Chrome, you can do this by right-clicking the page and selecting Inspect Element or by hitting ‘Control-Shift-C’ or ‘Command-Shift-C’.
    • If you are not already there, navigate to the ‘Console’ tab of the developer tools.
    • Refer to your copy of REDCapIds.txt and identify the latest included ID.
    • Copy from your console output beginning at the first new ID.
    • Paste into REDCapIds.txt.

    Note: If you want to run the script without making a bookmark, you can paste the contents of REDCapIDPull.js into your browser’s console and run it from there. The majority of the instructions above still apply.

    License

    This project is licensed under the MIT License – see the LICENSE file for details

    Authors

    Acknowledgements

    My time working on this project is funded by the NIH via Northwestern University’s Institute for Sexual and Gender Minority Health and Wellbeing. Visit the RADAR Project’s DokuWiki Codebook if you are interested in the study collecting this data.

    Visit original content creator repository
    https://github.com/mchlltt/radar-cleaning

  • My_Day_Capstone

    My Day – Android Application Readme

    1. Introduction

    My Day is an Digital Diary Application that is built on Android Framework. It helps users to

    -Make daily entries and delete any past entry

    -Update a past Entry

    -Adding rich media content like Images and Videos

    -Support for adding metadata like GeoTag and Weather Information

    -Search for any Entry by date

    -Set Favourites Entry

    -Adding Screen Widget

    -Enable Google Drive AutoBackup for Database and Preferences (requires Sign In using Google+ Account)

    Developer Features
    -Firebase Authentication

    -Crash Reporting

    -Test Labs

    -Analytics

    -Push Notifications

    1. OS Requirements

    My Day for Android is supported on all devices running Android Marshmallow (API Level 23) and above.
    It can be installed, but is untested on Android Lollipop and Kitkat.
    All Android Versions below Kitkat are unsupported.

    1. Installation

    My Day has two build types: Deug and Release.
    For testing and demonstration uses, please use the Debug Verison which is currently on build version 1. Beta Testing
    For production runs, please use the Release Version which is currently on build version 1. on Stable Channels

    3.1 To install Debug version, follow the given steps
    	a. Sign up on openWeatherMap.org and obtain an API Key using the website the website https://home.openweathermap.org/users/sign_up
    	b. Goto and install Android Studio along with SDK tools for API Level 25. At the time of this writing, Android Studio is Version 2.3.3
    		Use the following link to download Android Studio	https://developer.android.com/studio/index.html
    	c. In Android Studio, goto File >New >Import from Version Control >Github and checkout the following repository
    		https://github.com/anujc4/My_Day_Capstone.git
    	d. Download the project and complete the Gradle Synchronization.
    	e. Change the View from Android to Project from the left side Pane.
    	f. In the Project View, navigate to app/src/main/java/com/simplicity/anuj/myday/Utility class and put the API Key in the variable API_KEY.
    	g. Enable Debugging options in your Mobile from Developer Tools in Settings. If you choose to run the project on an emulator, skip this step.
    	h. Run the project by using Command Shift+F10 or the Play button in top bar.
    	i. After the Gradle Build completes, the App will start running on your device.
    
    3.2 To install the Release verison, simply goto the given URL from your Android Device in which you want to install My Day
    		https://goo.gl/w6zSXp
    
    1. Advanced Configuration

    MyDay has advanced cloud integration with features for Crash Reporting, Analytics, Cloud Authentication and Test Labs. These features are intended solely for the Developer and are not available for public use.

    Visit original content creator repository
    https://github.com/anujc4/My_Day_Capstone