unique_ptr basic implementation for single objects

This is an implementation to simulate the basic functionality of unique_ptr.
This doesn’t provide features like custom deleter and make_unique().

I would really appreciate any feedback to improve the below code, any other api’s that I should be providing etc.


#ifndef MY_UNIQUE_PTR_H_ #define MY_UNIQUE_PTR_H_  #include <utility>  namespace kapil {   template <typename T>   class unique_ptr final {     private:       T* ptr_;       unique_ptr(const unique_ptr&) = delete;               // Make unique_ptr non copy constructible       unique_ptr& operator = (const unique_ptr&) = delete;  // Make unique_ptr non copy assignable      public:       explicit unique_ptr (T* ptr = nullptr) noexcept         : ptr_{ptr} { }        unique_ptr(unique_ptr<T>&& rval) noexcept               // Move constructor         : ptr_{rval.ptr_} {         rval.ptr_ = nullptr;       }        unique_ptr& operator = (unique_ptr&& rhs) noexcept {   // Move assignment         delete ptr_;         ptr_ = rhs.ptr_;         rhs.ptr_ = nullptr;         return *this;       }        ~unique_ptr() noexcept {         delete ptr_;       }         T* release() noexcept {         T* old_ptr = ptr_;         ptr_ = nullptr;         return old_ptr;       }        void reset(T* ptr = nullptr) noexcept {         delete ptr_;         ptr_ = ptr;       }        void swap(unique_ptr& rhs) noexcept {         std::swap(ptr_, rhs.ptr_);       }        T* get() const noexcept {         return ptr_;       }        explicit operator bool() const noexcept {         return (ptr_ != nullptr);       }        T& operator * () const {         return *ptr_;       }        T* operator -> () const noexcept {         return ptr_;       }        friend bool operator == (const unique_ptr& lhs, const unique_ptr& rhs) {         return lhs.get() == rhs.get();       }        friend bool operator != (const unique_ptr& lhs, const unique_ptr& rhs) {         return !(lhs == rhs);       }   };    template <typename T>   void swap(unique_ptr<T>& lhs, unique_ptr<T>& rhs) {     lhs.swap(rhs);   } } //kapil  #endif 

Move Objects around cube

I need to move an object around a cube, to reach one of their sides like the image below.

enter image description here

I’m using a Raycast pointing down, when the raycast hit the cube I move the capsule to the center of the cube and I rotate it then to hit the next cube, but I can’t figured out how to achive this in the right way.

I wrote this, but everything is happening at the same time, and the move it’s not what it suppose it should be.

Quaternion rotate = Quaternion.Euler(0, 0, -90); Vector3 down = new Vector3 {     x = hit.transform.position.x,     y = hit.transform.position.y - .51f,     z = hit.transform.position.z }; transform.position = Vector3.MoveTowards(transform.position, down, 1.25f * Time.deltaTime); transform.localRotation = Quaternion.RotateTowards(transform.localRotation, rotate, 50 * Time.deltaTime); 

Any ideas, or improvements?

Btw, I forgot to mention the capsule is child of an empty gameobject to rotate the capsule around the cube using the same position of the hitted cube.

How can I rotate multiple objects at a time on Draw.io?

Alright, so I’m creating a card game, and there’s an icon and number on the top left of the card. On the bottom right, it should be mirrored so that if the card is dealt upside-down, time is not wasted. A good example is standard playing cards with the numbers and royals mirrored on both sides.

My icon consists of multiple shapes in different rotations (20,5,350,335 degrees), so it would be tedious to manually rotate. Example: https://gyazo.com/1951f9bf82435518fe19a070d54b5ae6

When I try to rotate all of them, there is no button for relative rotation — I can only enter an absolute rotation such as 90 degrees in the format panel, and then my icon is messed up.

For now, I ended up manually rotating all of them and changing the coordinates so that the manual rotations would fit as a whole. Maybe I might be wasting my time, though.

Filtering objects by date in MS Graph

I’m trying to get a list of all users who were created after a certain date.

I can use the endpoint below to get all users and then extend it again to request the user created date. In the graph explorer this only shows my date the rest are blank but I’m guessing this is down to permissions so I’m not concerned as this will be running in an SPFx web part with requested Graph permissions

https://graph.microsoft.com/v1.0/users https://graph.microsoft.com/v1.0/users?$ select=id, displayName, jobTitle, createdDateTime

Regardless of any filter I enter, see examples below, I never get any response on an error saying “Syntax error at position 26 in ‘createdDateTime gt 2018-08-02T13:01:13Z'”

https://graph.microsoft.com/v1.0/users?$ select=id, displayName, jobTitle, createdDateTime&$ filter= createdDateTime gt 2018-01-01 https://graph.microsoft.com/v1.0/users?$ select=id, displayName, jobTitle, createdDateTime&$ filter= createdDateTime gt 2018-08-02T13:01:13Z

I want to be able to find all users created after a certain date but can’t filter the user results on this date property it only works with basic details like displayName eq ‘Raymond Little’

How to refer to Applescript library objects with spaces in the name

I’m trying to write an Applescript that accesses EyeTV (yes, I still have one running!). I’m trying to list the recordings in the programs window. From the library:

application n [see also Standard Suite] : the EyeTV application   elements    contains player_windows, programs, recordings, channels, favorites lists.   properties    current recording (double integer, r/o) : unique id of the current (frontmost) recording. Returns 0 if there is none.   programs window (programs_window, r/o) : schedule dialog 

Further down in the dictionary is:

programs_window n [inh. window] : window containing the list of programs and recordings   elements    contains programs, recordings.   properties    selection (list of list) : A list containing every selected recording, channel or schedule (program) in the programs window, depending on what the current category is. 

If I right click the library and choose “New script” it will helpfully start the script for me:

tell application "EyeTV"  end tell 

I then add the line that is the problem:

tell application "EyeTV"     set recordList to recordings of programs window end tell 

If I compile this I get “Syntax Error Expected end of line but found class name.”

If I use programs_window instead, on running the script the error will be The variable programs_window is not defined.

I found a script someone else has written to export recordings from EyeTV to Plex, and it uses programs window. If I copy and paste the whole script and try to compile it I again receive the error Syntax Error Expected end of line but found class name.

I’m unsure how to proceed. Should I be referring to the programs window property of the application or the programs_window class? How can I get rid of the errors?

I have a copy of the AppleScript Language Guide but it seems to say nothing on the topic of application libraries.

Any help with this would be much appreciated.

Patterns for loading related objects in memory (without an ORM)

I am using ADO.NET to read a bunch of data from the database into in-memory objects.

This is my domain model:

// Question.cs public class Question {     public int ID { get; set; }     public string Title { get; set; }     public string Description { get; set; }     public IEnumerable<Tag> Tags { get; set; } }  // Tag.cs public class Tag  {     public int ID { get; set; }     public string Name { get; set; } } 

On retrieving the list of Questions, I would like to fetch the related tags for each question. I am able to do this as follows:

// QuestionRepository.cs  public IList<Question> FindAll() {     var questions = new List<Question>();      using (SqlConnection conn = DB.GetSqlConnection())     {         using (SqlCommand cmd = conn.CreateCommand())         {             cmd.CommandText = "select * from questions";              SqlDataReader reader = cmd.ExecuteReader();              while (reader.Read())             {                 Question question = new Question();                 // Populate the question object using reader                 question.Load(reader);                  questions.Add(question);             }             reader.Close();         }      }     return questions; }   // Question.cs public void Load(SqlDataReader reader) {     ID = int.Parse(reader["ID"].ToString());     Title = reader["Title"].ToString();     Description = reader["Description"].ToString();      // Use Tag Repository to find all the tags for a particular question     Tags = tagRepository.GetAllTagsForQuestionById(ID);  }      return questions; }  // TagRepository.cs public List<Tag> GetAllTagsForQuestionById(int id) {     List<Tag> tags = new List<Tag> ();     // Build sql query to retrive the tags     // Build the in-memory list of tags      return tags; } 

My question is, are there any best practices/patterns for fetching related objects from the database?

Most of the SO questions I came across for loading related data provide the solution for entity framework. There is no answer for this duplicate question.

Even though my code works, I would like to know other ways to do the same. The closest explanation I came across that’s targeting my particular problem was Martin Fowler’s Lazy Load pattern, which I believe, will result in following implementation:

public class Question {     private TagRepository tagRepo = new TagRepository();     private IList<Tag> tags;      public int ID { get; set; }     public string Title { get; set; }     public string Description { get; set; }     public IEnumerable<Tag> Tags {         get         {             if (tags == null)             {                 tags = tagRepo.GetAllTagsForQuestionById(ID);             }             return tags;         }     }   } 

Are there any other alternatives?

rayTest for cutted by stencil objects

I have red rectangle based on which I am cutting (using opengl stencil) all of the green rectangles, like shown in the following screenshots

a) before cut enter image description here

b) after cut

enter image description here

When I run rayTest(bullet physics ) it happened that those objects that are cutted is passing the test. Well, it is not really surprise as I am initializing them in dynamic world.

Do you know how to ignore those objects which is cutted by stencil when you run rayTest ? I need at least general idea how to do it.

How can I create objects automaticaly and have control over them during runtime?

I know how to make instances and objects but only in code and predefined. But how can I make new objects as the program is running ?

Let’s say someone plays a game real-time strategy game where he creates a number of new units. The player chooses the number of units and each unit can be manipulated individually (for example can move to a different location).

I have a realy hard time to imagine the way of name assignment to those new objects and how the program later refferences to them without explicitly defined code.

Please give examples in Python or C++ as they are the only languages I know.

Javascript – ShellSort of array of tweet objects

I’m trying to sort tweet objects according to the number of user’s followers. The data and object keys are custom from a mysql database containing data that I’ve been collecting for an app im building. I have an array called dstore, of Individual objects that look as follows :

    {tweet_text: "so I'm a bit surprised that people are... surprised. that the "action plan" to cool Toronto housing is just...meetings." user_FollowersCount: "1415" user_ProfileImageUrl: "http://pbs.twimg.com/profile_images/821936571842707456/gPPRWsyS_normal.jpg" user_ScreenName: "RosalindR"} 

The following is the sort function but i keep ending up with the objects not being sorted

public shellsrt(dstore){     var gaps = [20,10,1];     for (var g = 0; g <  gaps.length; ++g) {        for(var i = gaps[g]; i < dstore.length; ++i)       {             var temp = dstore[i];             var followcount = parseInt(temp['user_FollowersCount']);             var j = i;              if(dstore[j - gaps[g]] !== undefined){                var gapdiff = parseInt(dstore[j - gaps[g]]['user_FollowersCount']);                 while( j >= gaps[g] && gapdiff > followcount )                  {                        if ( dstore[gapdiff] != undefined) {                          dstore[j] = dstore[gapdiff];                                    }                              j -= gaps[g];                 }          }            dstore[j] = temp;                            }   }   console.log(dstore);    //return dstore; 


Could we characterize injective objects in the category of $G$-equivariant sheaves?

Let $ k$ be a field and $ X$ be a topological space. We consider Sh$ (X)$ , the category of sheaves of $ k$ -vector spaces on $ X$ .

Let $ G$ be a topological group which act on $ X$ continuously from the left. Consider the simplicial space $ [G\backslash X]_{\cdot}$ where $ $ [G\backslash X]_n=\underbrace{G\times \ldots \times G}_{n\text{ copies of }G\text{‘s}}\times X $ $ with structural maps $ $ d_0(g_1,\ldots, g_n,x)=(g_2,\ldots,g_n,g_1^{-1}x); $ $ $ $ d_i(g_1,\ldots, g_n,x)=(g_1,\ldots, g_ig_{i+1},\ldots, g_n,x), ~1\leq i\leq n-1; $ $ $ $ d_n(g_1,\ldots, g_n,x)=(g_1,\ldots, g_{n-1},x); $ $ and $ $ s_0(g_1,\ldots, g_n,x)=(e,g_1,\ldots, g_n,x); $ $ $ $ s_i(g_1,\ldots, g_n,x)=(g_1,\ldots, g_i,e , g_{i+1},\ldots, g_nx),~1\leq i\leq n-1; $ $ $ $ s_n(g_1,\ldots, g_n,x)=(g_1,\ldots, g_n,e,x). $ $

A $ G$ -equivariant sheaf on $ X$ is a pair $ (\mathcal{F},\theta)$ , where $ \mathcal{F}\in \text{Sh}(X)$ and $ \theta$ is an isomorphism $ $ \theta: d_0^*\mathcal{F}\overset{\sim}{\to} d_1^*\mathcal{F}, $ $ satisfying the cocycle condition $ $ d_2^*\theta\circ d_0^*\theta=d_1^*\theta, \text{ and } s_0^*\theta=\text{id}_{\mathcal{F}}. $ $ We denote the category of $ G$ -equivariant sheaves on $ X$ by $ \text{Sh}_G(X)$ . It is clear that $ \text{Sh}_G(X)$ is an abelian category and the forgetful functor For$ : \text{Sh}_G(X)\to \text{Sh}(X)$ is exact.

I am interested in the injective objects in $ \text{Sh}_G(X)$ . We know that in general, $ \text{For}: \text{Sh}_G(X)\to \text{Sh}(X)$ does not preserve injective objects, unless $ G$ is discrete.

Here are my questions

In the case that $ G$ is discrete, $ \mathcal{F}$ is injective as a sheaf is a necessary but not sufficient condition that $ (\mathcal{F},\theta)$ is an injective object in $ \text{Sh}_G(X)$ . Then what are additional requirements to make sure that $ (\mathcal{F},\theta)$ is injective?

In then general case that $ G$ is not discrete, what are injective objects in $ \text{Sh}_G(X)$ ?