Skip to content

Instantly share code, notes, and snippets.

View alleysark's full-sized avatar

alleysark alleysark

View GitHub Profile
let v = vec!["apple", "apple", "apple", "banana", "orange"];
let target = String::from("apple");
let mut it = v.into_iter().skip_while(|s| s == &&target); // or predicate can also be |s| **s == target
println!("{:?}", it.next());
let mut it = s.chars();
{
let mut jt = it.by_ref().peekable();
if jt.peek() == Some(&'H') {
jt.next();
}
}
println!("{:?}", it.next());
let mut it = s.chars();
let mut jt = it.clone().peekable();
if jt.peek() == Some(&'H') {
jt.next();
it.next(); // <- duplication of code :(
}
@alleysark
alleysark / rust-chars-peekable-move.rs
Last active May 11, 2018 13:59
Chars to Peekable iterator move semantic
let s = String::from("Hello, rust");
let mut it = s.chars();
let mut jt = it.peekable();
it.next(); // <- value used here after move!!
@alleysark
alleysark / Draw3DAgentComponent-use-case.cpp
Created May 3, 2017 11:22
Explain how to use the Draw3DAgentComponent
Draw3DAgent->CreateDynMeshElemDelegate.BindLambda(
[this](const FSceneView* View, class FPrimitiveDrawInterface* PDI, const FMatrix& LocalToWorld)
{
FVector CameraX, CameraY;
UDraw3DAgentComponent::GetCameraAxis(View, CameraX, CameraY);
FVector Loc = GetActorLocation();
DrawCircle(PDI, Loc, CameraX, CameraY, FLinearColor::Red, 20.f, 16, SDPG_Foreground, 3.f);
PDI->DrawLine(Loc, Loc + FVector::ForwardVector * 10.f, FLinearColor::Red, SDPG_Foreground);
#include "Sandbox.h"
#include "Draw3DAgentComponent.h"
UDraw3DAgentComponent::UDraw3DAgentComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bHiddenInGame = false;
bCastDynamicShadow = false;
bDrawOnlyIfSelected = false;
#pragma once
#include "Draw3DAgentComponent.generated.h"
UENUM(BlueprintType)
enum class ESceneDepthPriorityGroupProxy : uint8
{
/** World scene DPG. */
SDPGP_World UMETA(DisplayName="World"),
/** Foreground scene DPG. */
SDPGP_Foreground UMETA(DisplayName="Foreground")