Tutorial by Examples: l

A program can easily waste time by calling a processor-intensive function multiple times. For example, take a function which looks like this: it returns an integer if the input value can produce one, else None: def intensive_f(value): # int -> Optional[int] # complex, and time-consuming cod...
By default STI model class name is stored in a column named type. But its name can be changed by overriding inheritance_column value in a base class. E.g.: class User < ActiveRecord::Base self.inheritance_column = :entity_type # can be string as well end class Admin < User; end Migr...
Having type column in a Rails model without invoking STI can be achieved by assigning :_type_disabled to inheritance_column: class User < ActiveRecord::Base self.inheritance_column = :_type_disabled end
In a basic implementation the task module must define a run/1 function that takes a list of arguments. E.g. def run(args) do ... end defmodule Mix.Tasks.Example_Task do use Mix.Task @shortdoc "Example_Task prints hello + its arguments" def run(args) do IO.puts "Hello ...
Create setup script ~/.perlbrew.sh: # Reset any environment variables that could confuse `perlbrew`: export PERL_LOCAL_LIB_ROOT= export PERL_MB_OPT= export PERL_MM_OPT= # decide where you want to install perlbrew: export PERLBREW_ROOT=~/perlbrew [[ -f "$PERLBREW_ROOT/etc/bashrc" ]...
Presumably, your program will do something. Add your working code to the project in place of Program.fs. In this case, our task is to draw spirograph curves on a Window Canvas. This is accomplished using Spirograph.fs, below. namespace Spirograph // open System.Windows does not automatically o...
You have to create a XAML file that defines the main window that contains our menu and drawing space. Here's the XAML code in MainWindow.xaml: <!-- This defines the main window, with a menu and a canvas. Note that the Height and Width are overridden in code to be 2/3 the dimensions of the...
The XAML file for the spirograph parameters is below. It includes three text boxes for the spirograph parameters and a group of three radio buttons for color. When we give radio buttons the same group name - as we have here - WPF handles the on/off switching when one is selected. <!-- This fi...
namespace Spirograph type MainWindow(app: App, model: Model) as this = inherit MainWindowXaml() let myApp = app let myModel = model let whenLoaded _ = () let whenClosing _ = () let whenClosed _ = () let menuExitHandler _ = System.Wind...
<!-- All boilerplate for now --> <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> </Application.Reso...
Transcript show: 'Hello World!'. This will print Hello World! to the Transcript window in Smalltalk. Transcript is the class that allows you to print to the Transcript window by sending the message show: to that object. The colon indicates that this message requires a parameter which is in this c...
Sleep On older Windows system, timeout is not available. However, we can use the sleep command. Usage sleep 1 Very self-explanatory; sleep for 1 second. However, sleep is a deperacted command and should be replaced by timeout. Availability This command is available on old Windows system. ...
In MVC, there are some scenerios where you want to specify an action for routing purposes, either for a link, form action, or a redirect to action. You can specify an action via the MVC namespace. When given a Controller, such as HomeController: public class HomeController : Controller { pub...
By unlisted package, I mean a package that is not available through Package Control (yet). So, you can't find it in packagecontrol.io. BUT, you can still install it using Package Control, so you'll get all the advantages. For example, they'll be automatically updated, just like a "regular&quot...
Main Component File: //our root app component import {Component, NgModule, ViewChild, ViewContainerRef, ComponentFactoryResolver, ComponentRef} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' import {ChildComponent} from './childComp.ts' @Component({ selector: ...
Read the data of Create And Write To A Stream back into a program. with Ada.Streams.Stream_IO; procedure Main is -- -- ... same type definitions as in referenced example -- Fruit_Colors : array (Fruit) of Color; use Ada.Streams.Stream_IO; F : File_Type; X : Fruit...
@echo off cls echo Please input the file path, surrounded by "double quotation marks" if necessary. REM If you don't want to redirect, escape the > by preceding it with ^ set /p filepath=^> echo Writing a random number echo %RANDOM% > %filepath% echo Reading the random n...
package main import "fmt" var V int func F() { fmt.Printf("Hello, number %d\n", V) } This can be built with: go build -buildmode=plugin And then loaded and used from your application: p, err := plugin.Open("plugin_name.so") if err != nil { panic(e...
The following example shows how a set of data obtained from a remote source can be rendered into a component. We make an AJAX request using fetch, which is build into most browsers. Use a fetch polyfill in production to support older browsers. You can also use any other library for making requests ...
Running the split command without any options will split a file into 1 or more separate files containing up to 1000 lines each. split file This will create files named xaa, xab, xac, etc, each containing up to 1000 lines. As you can see, all of them are prefixed with the letter x by default. If ...

Page 736 of 861