Tutorial by Examples

Bubble sorting with rules and replacements: list = {1, 4, 2, 3, 6, 7, 8, 0, 1, 2, 5, 4} list //. {fsts___, x_, y_, lsts___} :> {fsts, y, x, lsts} /; y < x (* Out[1] := {1, 4, 2, 3, 6, 7, 8, 0, 1, 2, 5, 4} Out[1] := {0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 8} *)
Suppose we have this file: test>>cat file 10.Gryffindor 4.Hogwarts 2.Harry 3.Dumbledore 1.The sorting hat To sort this file numerically, use sort with -n option: test>>sort -n file This should sort the file as below: 1.The sorting hat 2.Harry 3.Dumbledore 4.Hogwa...
Suppose we have this file: test>>cat Hogwarts Harry Malfoy Rowena Helga Gryffindor Slytherin Ravenclaw Hufflepuff Hermione Goyle Lockhart Tonks Ron Snape Olivander Newt Ron Goyle Flitwick ...
Since BackAndroid is deprecated. Use BackHandler instead of BackAndroid. import { BackHandler } from 'react-native'; {...} ComponentWillMount(){ BackHandler.addEventListener('hardwareBackPress',()=>{ if (!this.onMainScreen()) { this.goBack(); return true; ...
<?php include "vendor/autoload.php"; $app = new \Slim\App(); $app->get('/hello', function () { echo "Hello, world"; }); $app->run();
In the following example echo on will take effect after the end of the brackets context is reached: @echo off ( echo on echo ## ) echo $$ In order to "activate" echo on in a brackets context (including FOR and IF commands) you can use FOR /f macro : @echo off setlocal ...
Anonymous functions technique uses the fact that CALL command uses internally GOTO when subroutine is called and abusing help message printing with variable double expansion: @echo off setlocal set "anonymous=/?" call :%%anonymous%% a b c 3>&1 >nul if "%0" == ...
Lets have the following file called library.cmd : @echo off echo -/-/- Batch Functions Library -/-/- :function1 echo argument1 - %1 goto :eof To execute only the :function1 without the code of the rest of the file you should put a label :function1 in the caller bat and use it lik...
import java.util.StringTokenizer; public class Simple{ public static void main(String args[]){ StringTokenizer st = new StringTokenizer("apple ball cat dog"," "); while (st.hasMoreTokens()) { System.out.println(st.nextToken()); } } ...
public static void main(String args[]) { StringTokenizer st = new StringTokenizer("apple,ball cat,dog", ","); while (st.hasMoreTokens()) { System.out.println(st.nextToken()); } } Output: apple ball cat dog
Semaphores are used to synchronize operations between two or more processes. POSIX defines two different sets of semaphore functions: 'System V IPC' — semctl(), semop(), semget(). 'POSIX Semaphores' — sem_close(), sem_destroy(), sem_getvalue(), sem_init(), sem_open(), sem_post(), sem_try...
Parent element html <child-component [isSelected]="inputPropValue"></child-component> Parent element ts export class AppComponent { inputPropValue: true } Child component ts: export class ChildComponent { @Input() inputPropValue = false; } Child compone...
The easiest way to connect via curl to a different server is to alter the hosts file on your machine. On Linux and Unix systems, the hosts file is located in /etc/hosts, while on Windows systems it will be located in c:\windows\system32\drivers\etc\hosts. Once you open the file with a text editor ...
The most effective way to resolve curl to a different server is to use the --resolve option. This option will insert the address into curl's DNS cache, so it will effectively make curl believe that's the address it got when it resolved the name. Like so: curl --resolve eaxmple.com:80:1.2.3.4 http:...
The "Host:" header is a normal way an HTTP client tells the HTTP server which server it speaks to. By passing custom modified "Host:" header you can have the server respond with the content of the site, even if you didn't actually connect to the host name. For example, if you ha...
Lets have the following example.bat and call it with arguments 1 ,2 and 3: @echo off ( shift shift echo %1 ) As the variable expansion will change after the the end brackets context is reached the output will be: 1 As this might be an issue when shifting inside brackets ...
from django.contrib.auth.models import User class UserAdmin(admin.ModelAdmin): list_display = ('email', 'first_name', 'last_name') list_filter = ('is_staff', 'is_superuser') admin.site.unregister(User) admin.site.register(User, UserAdmin) We need to unregister before regis...
First is first, ensure that USE_TZ = True in your settings.py file. Also set a default time zone value to TIME_ZONE such as TIME_ZONE='UTC'. View a complete list of timezones here. If USE_TZ is False, TIME_ZONE will be the time zone that Django will use to store all datetimes. When USE_TZ is enable...
Python's datetime.datetime objects have a tzinfo attribute that is used to store time zone information. When the attribute is set the object is considered Aware, when the attribute is not set it is considered a Naive. To ensure that a timezone is naive or aware, you can use .is_naive() and .is_awar...
packed is a variable attribute that is used with structures and unions in order to minimize the memory requirements. #include <stdio.h> struct foo { int a; char c; }; struct __attribute__((__packed__))foo_packed { int a; char c; }; int main() { printf("...

Page 1285 of 1336