// Let's take an arbitrary piece of data, a 4-byte integer in this case
let some_data: u32 = 14;
// Create a constant raw pointer pointing to the data above
let data_ptr: *const u32 = &some_data as *const u32;
// Note: creating a raw pointer is totally safe but dereferencing a raw pointe...
// Let's take a mutable piece of data, a 4-byte integer in this case
let mut some_data: u32 = 14;
// Create a mutable raw pointer pointing to the data above
let data_ptr: *mut u32 = &mut some_data as *mut u32;
// Note: creating a raw pointer is totally safe but dereferencing a raw pointe...
Just like in C, Rust raw pointers can point to other raw pointers (which in turn may point to further raw pointers).
// Take a regular string slice
let planet: &str = "Earth";
// Create a constant pointer pointing to our string slice
let planet_ptr: *const &str = &planet ...
Rust has a default formatter for pointer types that can be used for displaying pointers.
use std::ptr;
// Create some data, a raw pointer pointing to it and a null pointer
let data: u32 = 42;
let raw_ptr = &data as *const u32;
let null_ptr = ptr::null() as *const u32;
// the {:p} mappi...
Overloading the addition operator (+) requires implement the std::ops::Add trait.
From the documentation, the full definition of the trait is:
pub trait Add<RHS = Self> {
type Output;
fn add(self, rhs: RHS) -> Self::Output;
}
How does it work?
the trait is implemented for...
Processing provides a method named line() to draw a line on the screen. This code draws a white 10 pixel line on black background.
void setup() {
size(500, 500);
background(0);
stroke(255);
strokeWeight(10);
}
void draw() {
line(0, 0, 500, 500);
}
The signature of m...
Using compose with a View, ViewModel and Model is an easy way to reuse and combine different Views and ViewModels.
Given the following View and ViewModel (applies to each alternative below):
src/greeter.html
<template>
<h1>Hello, ${name}!</h1>
</template>
src/gree...
There are quite a number situations where one has huge amounts of data and using which he has to classify an object in to one of several known classes. Consider the following situations:
Banking: When a bank receives a request from a customer for a bankcard, the bank has to decide whether to issue...
Uses C standard format codes.
from datetime import datetime
datetime_for_string = datetime(2016,10,1,0,0)
datetime_string_format = '%b %d %Y, %H:%M:%S'
datetime.strftime(datetime_for_string,datetime_string_format)
# Oct 01 2016, 00:00:00
malloc() often calls underlying operating system functions to obtain pages of memory. But there is nothing special about the function and it can be implemented in straight C by declaring a large static array and allocating from it (there is a slight difficulty in ensuring correct alignment, in pract...
Let's say we have 8 houses. We want to setup telephone lines between these houses. The edge between the houses represent the cost of setting line between two houses.
Our task is to set up lines in such a way that all the houses are connected and the cost of setting up the whole connection is mini...
FullCalendar can be downloaded from it's website: https://fullcalendar.io/download/
from NPM:
$ npm install fullcalendar
from Bower:
$ bower install fullcalendar
or CDNJS:
//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.0.1/fullcalendar.min.js
//cdnjs.cloudflare.com/ajax/libs/fullca...
After enabling and creating migrations there might be a need to initially fill or migrate data in your database. There are several possibilities but for simple migrations you can use the method 'Seed()' in the file Configuration created after calling enable-migrations.
The Seed() function retrieves...
class Program
{
static void Main(string[] args)
{
//Initialize a new container
WindsorContainer container = new WindsorContainer();
//Register IService with a specific implementation and supply its dependencies
container.Register(Component.For<ISer...
When run with no arguments, this program starts a TCP socket server that listens for connections to 127.0.0.1 on port 5000. The server handles each connection in a separate thread.
When run with the -c argument, this program connects to the server, reads the client list, and prints it out. The clie...
Sometimes we want to use a where query on a a collection of records returned which is not ActiveRecord::Relation.Hence we get the above error as Where clause is know to ActiveRecord and not to Array.
There is a precise solution for this by using Joins.
EXAMPLE:-
Suppose i need to find all user ...