What Does The 'P-N' and Its Variants Represent in Bootstrap V4

What does the `p-N` and its variants represent in Bootstrap v4?

They are the new spacing utility classes. I think they're very intuitive:

  • p-* is for padding all sides.
  • m-* is for margin all sides.
  • pl-* is for padding left.
  • mt-* is for margin top.
  • mr-auto is for margin right auto.

Spacing Utils Demo

There are also display utilties.

d-block, d-flex, d-inline-block, d-none etc...

What's the meaning of ml in bootstrap 4?

It's short for: margin-left

So ml-auto means margin-left: auto which aligns an element to the right.

Type erasing type erasure, `any` questions?

Here's my solution. It looks shorter than Yakk's, and it does not use std::aligned_storage and placement new. It additionally supports stateful and local functors (which implies that it might never be possible to write super_any<&print>, since print could be a local variable).

any_method:

template<class F, class Sig> struct any_method;

template<class F, class Ret, class... Args> struct any_method<F,Ret(Args...)> {
F f;
template<class T>
static Ret invoker(any_method& self, boost::any& data, Args... args) {
return self.f(boost::any_cast<T&>(data), std::forward<Args>(args)...);
}
using invoker_type = Ret (any_method&, boost::any&, Args...);
};

make_any_method:

template<class Sig, class F>
any_method<std::decay_t<F>,Sig> make_any_method(F&& f) {
return { std::forward<F>(f) };
}

super_any:

template<class...OperationsToTypeErase>
struct super_any {
boost::any data;
std::tuple<typename OperationsToTypeErase::invoker_type*...> operations = {};

template<class T, class ContainedType = std::decay_t<T>>
super_any(T&& t)
: data(std::forward<T>(t))
, operations((OperationsToTypeErase::template invoker<ContainedType>)...)
{}

template<class T, class ContainedType = std::decay_t<T>>
super_any& operator=(T&& t) {
data = std::forward<T>(t);
operations = { (OperationsToTypeErase::template invoker<ContainedType>)... };
return *this;
}
};

operator->*:

template<class...Ops, class F, class Sig,
// SFINAE filter that an op matches:
std::enable_if_t< std::disjunction< std::is_same<Ops, any_method<F,Sig>>... >{}, int> = 0
>
auto operator->*( super_any<Ops...>& a, any_method<F,Sig> f) {
auto fptr = std::get<typename any_method<F,Sig>::invoker_type*>(a.operations);
return [fptr,f, &a](auto&&... args) mutable {
return fptr(f, a.data, std::forward<decltype(args)>(args)...);
};
}

Usage:

#include <iostream>
auto print = make_any_method<void(std::ostream&)>(
[](auto&& self, auto&& os){ os << self; }
);

using printable_any = super_any<decltype(print)>;

printable_any bob = 7; // sets up the printing data attached to the any

int main() {
(bob->*print)(std::cout); // prints 7
bob = 3.14159;
(bob->*print)(std::cout); // prints 3.14159
}

Live

File input 'accept' attribute - is it useful?

The accept attribute is incredibly useful. It is a hint to browsers to only show files that are allowed for the current input. While it can typically be overridden by users, it helps narrow down the results for users by default, so they can get exactly what they're looking for without having to sift through a hundred different file types.

Usage

Note: These examples were written based on the current specification and may not actually work in all (or any) browsers. The specification may also change in the future, which could break these examples.

h1 { font-size: 1em; margin:1em 0; }h1 ~ h1 { border-top: 1px solid #ccc; padding-top: 1em; }
<h1>Match all image files (image/*)</h1><p><label>image/* <input type="file" accept="image/*"></label></p>
<h1>Match all video files (video/*)</h1><p><label>video/* <input type="file" accept="video/*"></label></p>
<h1>Match all audio files (audio/*)</h1><p><label>audio/* <input type="file" accept="audio/*"></label></p>
<h1>Match all image files (image/*) and files with the extension ".someext"</h1><p><label>.someext,image/* <input type="file" accept=".someext,image/*"></label></p>
<h1>Match all image files (image/*) and video files (video/*)</h1><p><label>image/*,video/* <input type="file" accept="image/*,video/*"></label></p>

COQ identity term which is not eq_refl

As you point out, (fun x => eq_refl x) 2 is not actually different from eq_refl 2, since both expressions compute to the same thing.

Answering your second question is a bit delicate, because it can be interpreted in many different ways. Here's one possibility (which I think is the one you had in mind):

Are there any type T and terms x y : T, such that there is a proof e of @eq T x y in the empty context that does not compute to @eq_refl T z (where z : T is the result of computing x and y)?

I believe that the answer to this question is no. It should be possible to prove it formally by arguing that, since Coq's theory is strongly normalizing, e must have a normal form e', and that all normal forms that have type eq must be eq_refl.

Note that, if drop the requirement that e is typed in the empty context, this does not hold anymore. For instance, consider the proof term of forall n, n + 0 = n.

Fixpoint plus_n_0 n : n + 0 = n :=
match n return n + 0 = n with
| 0 => eq_refl 0
| S n' => match plus_n_0 n' in _ = m return S (n' + 0) = S m with
| eq_refl => eq_refl (S (n' + 0))
end
end.

In the successor branch, we use the match to produce a proof of S (n' + 0) = S n' which does not compute to eq_refl. This happens because the match cannot reduce the plus_n_0 n' term, since it's a function applied to a variable. However, if we apply plus_n_0 to any concrete natural number (say, 1729), the resulting proof will compute to eq_refl 1729 (try it!).

Another thing worth pointing out is that, when arguing that every closed proof of equality computes to eq_refl, we had to reason outside of Coq's logic, appealing to a normalization argument that we cannot phrase as a Coq proposition: note that, because Coq identifies terms up to convertibility, there's no way of writing a proposition P : nat -> Prop such that P n holds if and only if n is a Coq term in normal form.

Given this fact, you may wonder if there's anyway of establishing that result inside Coq's logic; that is,

forall T (x : T) (e : x = x), e = eq_refl x,

or, paraphrased in English, "every proof of equality is equal to eq_refl". As it turns out, this statement is independent of Coq's logic, which means that it cannot be proved nor disproved within Coq itself.

It may seem at first that this contradicts what I said earlier. But recall that we can always add new axioms to Coq's logic if they don't contradict results that can be proved inside the logic. This means that it is perfectly fine to assume that there exists some type T, some term x : T, and some proof e of x = x such that e <> eq_refl x. If we added this axiom, then the argument I gave earlier would no longer apply, since there would be normal forms of equality proofs that would be syntactically different from eq_refl (namely, e).

The fact that we cannot establish this result inside Coq's logic (and similar formal systems, such as Martin-Löf's type theory) is exactly what enables homotopy type theory. HoTT postulates the existence of the univalence axiom, which allows one to produce provably different proofs of equality.

Edit It is important to remember that there are two notions of equality in Coq: definitional equality (i.e., terms that are equal by simplification) and propositional equality (i.e., terms that we can relate by =). Definitionally equal terms are interchangeable for Coq, whereas propositionally equal terms must be exchanged with an explicit rewriting step (or using the match statement, as seen above).

I was a bit lax in the discussion above about the difference between these two variants. There are cases where proofs of equality are propositionally equal even if they aren't so definitionally. For instance, consider the following alternate proof of reflexivity for nat:

Fixpoint eq_refl_nat (n : nat) : n = n :=
match n return n = n with
| 0 => eq_refl 0
| S n' => match eq_refl_nat n' in _ = m return S n' = S m with
| eq_refl => eq_refl (S n')
end
end.

The term eq_refl_nat is not definitionally equal to eq_refl: we cannot obtain eq_refl from eq_refl_nat just by simplification. However, both are propositionally equal: as it turns out, for nat, it is possible to show that forall n (e : n = n), e = eq_refl. (As I mentioned above, this cannot be shown for arbitrary Coq types.)

char buf[]/pointer issues with the start address of the array changing

The following files all compile cleanly.

Im on ubuntu linux 14.04 using gcc -Wall -Wextra -pedantic -Wconversion -std=c99 -c to compile each file

Notice there were many small changes to the code to obtain the clean compiles.

You can perform a 'diff' 'cmp' or similar function to highlight the changes made to get the clean compiles.

Some of the changes involved:

  1. corrected the usage statements in the printusage() function
  2. corrected the list of #include statements
  3. corrected declaration of i as unsigned char rather than char
  4. corrected declaration of certain other variables from int to either ssize_t or size_t, as needed
  5. removed the two different typedef's for speed_t so the code uses the typedef in the thermos.h header file
  6. changed return type on a function from uint32_t to int32_t so function could return a proper -1 value when errors occur
  7. corrected the indenting of the code for consistency/readability
  8. for function: BP_WriteToPirate() carried forward the correct second parameter type from int* to unsigned int*
  9. properly cast parameters to t_opt.c_... flags to unsigned int rather than the default int, but only for the not defined NJC
  10. modified the contents of certain error messages to include the strerror(errno) string
  11. corrected exit from serial_read() to always NUL terminate the input buffer
  12. added #defines for FALSE and TRUE
  13. when inputting speed from the parameter list, used atol() rather than atoi() so data type would match the typedef speed_t
  14. one still existing problem is the actual value pasted to the cfsetispeed(&t_opt, speed); and cfsetospeed(&t_opt, speed);` functions must be from the set defined in thermos.h not the actual baud rate, because the parameter must be one of the valid bitmap'd values not some long int.

Caveat: my system has no modem nor 'bus pirate` so could not perform extensive testing however: with no (or bad) parameters: the following was output:

-------------------------------------------------------

Bus Pirate binary mode SPI SNIFFER utility v0.2 (CC-0)
http://dangerousprototypes.com

-------------------------------------------------------

&buffer = 0x7ffed4128010
ERROR: Invalid argument(s).

Help Menu

-------------------------------------------------------

Usage:
./untitled -d device -e 1 -p 0

Example Usage: ./untitled -d /dev/ttyUSB0 -s 115200 -e 1 -p 0

Where: -d device is port e.g. /dev/ttyUSB0
-s Speed is port Speed default is 115200
-e ClockEdge is 0 or 1 default is 1
-p Polarity is 0 or 1 default is 0
-r RawData is 0 or 1 default is 0

-------------------------------------------------------

with reasonably good parameters, the following was output:

./untitled -d /dev/ttyUSB0 -s 115200 -e 1 -p 0 -r 0 
-------------------------------------------------------

Bus Pirate binary mode SPI SNIFFER utility v0.2 (CC-0)
http://dangerousprototypes.com

-------------------------------------------------------

&buffer = 0x7ffd5a4b35f0
A &buffer = 0x7ffd5a4b35f0
Parameters used: Device = /dev/ttyUSB0, Speed = 115200, Clock Edge= 1, Polarity= 0
Opening Bus Pirate on /dev/ttyUSB0 at 115200bps...
Could not open serial port due to: No such file or directory.Error opening serial port

When I modified the code to ignore the failure to open the serial port then this resulted: with the same counting sequence repeated forever.

0 Sync (0x00/0)
0 Sync (0x00/1)
0 Sync (0x00/2)
...
0 Sync (0x00/120)
0 Sync (0x00/121)
0 Sync (0x00/122)
0 Sync (0x00/0)

and there was no shift in the stack pointer so the buffer[] array did not move

main.c

/*
* This file is part of the Bus Pirate project (http://code.google.com/p/the-bus-pirate/).
*
* Written and maintained by the Bus Pirate project and http://dangerousprototypes.com
*
* To the extent possible under law, the project has
* waived all copyright and related or neighboring rights to Bus Pirate. This
* work is published from United States.
*
* For details see: http://creativecommons.org/publicdomain/zero/1.0/.
*
* This program 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.
*/

// added
#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // getopt(), usleep()
#include <string.h> // strdup()
#include <errno.h>

#include <stdint.h>
#include <signal.h>

#define FALSE (0)
#define TRUE (~FALSE)

#ifdef WIN32
#include <conio.h>
#include <windef.h>
#else
//#include <curses.h>
#endif

#include "buspirate.h"
#include "serial.h"

int modem; //set this to TRUE of testing a MODEM
int verbose;
int disable_comport = 0; //1 to say yes, disable comport, any value to enable port default is 0 meaning port is enable.
int dumphandle; // use by dump file when using the -d dumfile.txt parameter
char *dumpfile;

#define SPI 0x01

int print_usage(char * appname)
{
//print usage
printf("\n\n");

// added '-d com1 in two places
printf("-------------------------------------------------------\n");
printf("\n");
printf(" Usage: \n");
printf(" %s -d device -e [0|1] -p [0|1] -d deviceName\n ",appname);
printf("\n");
printf(" Example Usage: %s -d /dev/ttyUSB0 -s 115200 -e 1 -p 0 \n",appname);
printf("\n");
printf(" Where: -d device is port e.g. /dev/ttyUSB0\n");
printf(" -s Speed is port Speed default is 115200 \n");
printf(" -e ClockEdge is 0 or 1 default is 1 \n");
printf(" -p Polarity is 0 or 1 default is 0 \n");
printf(" -r RawData is 0 or 1 default is 0 \n");
printf("\n");

printf("\n");

printf("-------------------------------------------------------\n");

return 0;
}

int main(int argc, char** argv)
{
int opt;
int fd;
int res;
int c;
int new_state;
int state = 0;

//char buffer[256] = { [0 ... 255] = 0x00 };
char buffer[256] = { 0x00 };
//char *buffer = malloc(sizeof(char) * 256);
unsigned char i; // was char i;

char *param_port = NULL;
char *param_polarity = NULL;
char *param_clockedge = NULL;
char *param_rawdata = NULL;
char *param_speed = NULL;
int speed;

printf("-------------------------------------------------------\n");
printf("\n");
printf(" Bus Pirate binary mode SPI SNIFFER utility v0.2 (CC-0)\n");
printf(" http://dangerousprototypes.com\n");
printf("\n");
printf("-------------------------------------------------------\n");
printf("\n\n");

fprintf(stderr, "&buffer = %p\n", buffer);

if (argc <= 1)
{
printf("ERROR: Invalid argument(s).\n\n");
printf("Help Menu\n");
print_usage(argv[0]);
exit(-1);
}

while ((opt = getopt(argc, argv, "ms:p:e:d:r:")) != -1)
{
// printf("%c \n",opt);
switch (opt)
{
case 'd': // device eg. com1 com12 etc
if ( param_port != NULL)
{
printf("Device/PORT error!\n");
exit(-1);
}
param_port = strdup(optarg);
break;

case 'e': // clock edge
if (param_clockedge != NULL)
{
printf("Clock Edge should be 0 or 1\n");
exit(-1);
}
param_clockedge = strdup(optarg);
break;

case 'p':
if (param_polarity != NULL)
{
printf("Polarity must be 0 or 1\n");
exit(-1);
}
param_polarity = strdup(optarg);
break;

case 's':
if (param_speed != NULL)
{
printf("Speed should be set: eg 115200 \n");
exit(-1);
}
param_speed = strdup(optarg);
speed = atoi(param_speed);
break;

case 'r': // raw data
if (param_rawdata != NULL)
{
printf("Raw Data should be 0 or 1\n");
exit(-1);
}
param_rawdata = strdup(optarg);
break;

case 'm': // modem debugging for testing
modem =TRUE; // enable modem mode
break;

default:
printf("Invalid argument %c", opt);
print_usage(argv[0]);
//exit(-1);
break;
}
} // end while

fprintf(stderr, "A &buffer = %p\n", buffer);

if (param_port==NULL)
{
printf("No serial port set\n");
print_usage(argv[0]);
exit(-1);
}

if (param_clockedge==NULL)
{
param_clockedge=strdup("1");
}

if (param_polarity==NULL)
{
param_polarity=strdup("0");
}

if (param_speed==NULL)
{
param_speed = strdup("115200");
speed = 115200;
}

if (param_rawdata==NULL)
{
param_rawdata=strdup("0");
}

printf("Parameters used: Device = %s, Speed = %s, Clock Edge= %s, Polarity= %s\n",param_port,param_speed,param_clockedge,param_polarity);

//
// Open serial port
//
printf(" Opening Bus Pirate on %s at %dbps...\n", param_port, speed);
fd = serial_open(param_port);
if (fd < 0)
{
fprintf(stderr, "Error opening serial port\n"); //serial_write( fd, "\x0E", 1);
//serial_write( fd, &'0x0E', 1);
return -1;
}

//
// Enter binary mode, then enter a protocol mode
//
serial_setup(fd, (speed_t) speed);

//printf(" Starting SPI sniffer...\n");
if (modem == TRUE)
{ // connected to modem for testing response

serial_write( fd, "ATI3\x0D\0",5 );
usleep(1);
res= serial_read(fd, buffer, sizeof(buffer));
printf("\n %s\n",buffer);

serial_write( fd, "ATI4\x0D\0",5 );
usleep(1);
res= serial_read(fd, buffer, sizeof(buffer));
printf("\n %s\n",buffer);

serial_write( fd, "ATI7\x0D\0",5 );
usleep(1);
res= serial_read(fd, buffer, sizeof(buffer));
printf("\n %s\n",buffer);
}

else
{
fprintf(stderr, " Configuring Bus Pirate...\n");
fprintf(stderr, "B &buffer = %p\n\n", buffer);
BP_EnableMode(fd, SPI); //enter BBIO then SPI
//
//Start sniffer
//

//configure according to user settings
//1000wxyz - SPI config, w=HiZ/3.3v, x=CKP idle, y=CKE edge, z=SMP sample
i = 0x80;

if(strncmp(param_clockedge, "1", 1)==0)
{
i |= 0x02;
}

if(strncmp(param_polarity, "1", 1)==0)
{
i |= 0x04;
}

fprintf(stderr, "C &buffer = %p\n", buffer);
BP_WriteToPirate(fd, &i);
fprintf(stderr, "D &buffer = %p\n", buffer);

// start the sniffer
fprintf(stderr, "start the sniffer\n");

// Yes this is goofy but it kept trying to writ 0xffffff82 instead of 0x0E
char t[] = { 0x0E, 0x00 };

serial_write( fd, t, 1);

//
// Done with setup
//
fprintf(stderr, "E &buffer = %p\n", buffer);

}

printf("Happy sniffing! Ctrl-C (^C) to stop.\n");

// 000011XX - Sniff SPI traffic when CS low(10 ^N)/all(01 ^M)
// 0x60 = ` 30khz
// 0x61 = a 125khz
// 0x67 = b 250khz
// 0x67 = c 1.0 Mhz
// 0x67 = d 2.0 Mhz
// 0x67 = e 2.6 Mhz
// 0x67 = f 4.0 Mhz
// 0x67 = g 8.0 Mhz
//
// Loop and print input from the serial port
/*
** ###
** ### @FIXME: Major issue with a SIGSEGV but I can't figure it out!
** ###
** ### If I attempt to use char buffer[256] it moves from one address to
** ### another in the code above (is that normal?). So I'm guessing
** ### something in the BP_WriteToPirate() (above) is wrong as this is where
** ### the change occurs. I've malloc'd a buffer of 256 bytes and the code
** ### seems happier (ie, no SIGSEGV but no solution either).
** ###
*/
fprintf(stderr, "X FD = %d &buffer = %p\n" , fd, buffer);

while(1)
{
usleep(1);
//res = serial_read(fd, ptr, 100);
res = serial_read(fd, buffer, 100);

if(res == -1)
{
// For some reason we get an error
// So close the port and reopen it
fprintf(stderr, "(%d) Read errno: %s\n", fd, strerror(errno));
if(errno == EBADF)
{ // 9
close(fd);

fd = serial_open(param_port);
if (fd < 0)
{
fprintf(stderr, "Error opening serial port\n");
return -1;
}

//
// Enter binary mode, then enter a protocol mode
//
serial_setup(fd, (speed_t) speed);
}
}

else if(res > 0)
{
for(c = 0; c < res; c++)
{
if(strncmp(param_rawdata, "1", 1)==0)
{
printf("%02X ", (uint8_t) buffer[c]);
}

else
{
switch(state)
{
default:
// fall through
case 0: // waiting CS active
if (buffer[c] == 0x5B)
{
printf("[");
new_state = 1;
}

else
{
printf("0 Sync (0x%02x/%d)\n", buffer[c], c);
new_state = 0;
}
break;

case 1: // check for data or CS inactive
if (buffer[c] == 0x5C)
{
new_state = 2;
}

else if (buffer[c] == 0x5D)
{
printf("]\n");
new_state = 0;
}

else
{
printf("1 Sync (0x%02x)\n", buffer[c]);
new_state = 0;
}
break;

case 2: // MPI
printf("0x%02X(", (uint8_t) buffer[c]);
new_state = 3;
break;

case 3: // MPO
printf("0x%02X)", (uint8_t) buffer[c]);
new_state = 1;
break;
} // end switch
state = new_state;
} // end if
} // end for
} // end if
} // ^C to stop

free(param_port);
free(param_speed);
return 0;
}

serial.c

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>

#include <string.h>

#include "serial.h"

extern int disable_comport;
extern char *dumpfile;

int serial_setup(int fd, speed_t speed)
{
struct termios t_opt;

#ifdef NJC
int s = tcgetattr(cm11, &oldsb);

if (s < 0)
{
perror("ttopen tcgetattr");
exit(1);
}

newsb = oldsb;
#ifndef BUSPIRATE_h_
#define BUSPIRATE_h_

#include <stdint.h>

int32_t BP_WriteToPirate(int fd, unsigned char * val);
void BP_EnableMode(int fd, char bbmode);

#endif

newsb.c_iflag = IGNBRK | IGNPAR;
newsb.c_oflag = 0;
newsb.c_lflag = ISIG;
newsb.c_cflag = (CLOCAL | B4800 | CS8 | CREAD);

for (s = 0; s < NCC; s++)
{
newsb.c_cc[s] = 0;
}

newsb.c_cc[VMIN] = 1;
newsb.c_cc[VTIME] = 0;

tcsetattr(cm11, TCSADRAIN, &newsb);
#else
/* set the serial port parameters */
fcntl(fd, F_SETFL, 0);
tcgetattr(fd, &t_opt);

cfsetispeed(&t_opt, speed);
cfsetospeed(&t_opt, speed);

t_opt.c_cflag |= (unsigned)(CLOCAL | CREAD);
t_opt.c_cflag &= (unsigned)~PARENB;
t_opt.c_cflag &= (unsigned)~CSTOPB;
t_opt.c_cflag &= (unsigned)~CSIZE;
t_opt.c_cflag |= (unsigned)CS8;
t_opt.c_lflag &= (unsigned)~(ICANON | ECHO | ECHOE | ISIG);
t_opt.c_iflag &= (unsigned)~(IXON | IXOFF | IXANY);
t_opt.c_oflag &= (unsigned)~OPOST;
t_opt.c_cc[VMIN] = 0;
//t_opt.c_cc[VTIME] = 10;
t_opt.c_cc[VTIME] = 1;

tcflush(fd, TCIFLUSH);

tcsetattr(fd, TCSANOW, &t_opt);
#endif
return 0;
} // end function: serial_setup

int serial_write(int fd, char *buf, int size)
{
ssize_t ret = 0;

ret = write(fd, buf, (size_t)size);

fprintf(stderr, "W> ");

for(int i = 0; i < size; i++)
{
fprintf(stderr, "0x%02x ", (unsigned char) buf[i]);
}

fprintf(stderr, "size = %d (%ld)\n", size, ret);

return (int)ret;
} // end function; serial_write

int serial_read(int fd, char *buf, int size)
{
ssize_t len = 0;
ssize_t ret = 0;
int timeout = 0;

while ( len < size)
{
//fprintf(stderr, "FD = %d &buffer = %p (%d)\n" , fd, buf, sizeof(buf));
ret = read(fd, buf+len, (size_t)(size-len));
if (ret == -1)
{
buf[len] = '\0';
return -1;
}

if (ret == 0)
{
timeout++;

if (timeout >= 10)
{
break; // Break out and return from this function
}

else
{
continue; // Just continue the loop
}
}

len += ret;
} // end while

//if( len > 255)
//{
// buf[255] = 0x00; // Buffer's length is 256
//}

//else
//{
buf[len] = 0x00;
//}
return (int)len;
} // end function: serial_read

int serial_open(char *port)
{
int fd;
fd = open(port, O_RDWR | O_NOCTTY);

if (fd == -1)
{
fprintf(stderr, "Could not open serial port due to: %s.", strerror( errno ) );
return -1;
}

return fd;
} // end function: serial_open

int serial_close(int fd)
{
close(fd);

return 0;
} // end function: serial_close

buspirate.c



Related Topics



Leave a reply



Submit