Skip to content

Instantly share code, notes, and snippets.

View codyhex's full-sized avatar
🎯
Focusing

He, Peng codyhex

🎯
Focusing
View GitHub Profile
def final_time(tasks, cooldown):
# this question is actually about putting a serialized tasks into parallel task Q
task_run_time = 1
lastExcStart = {} # coreId:lastTask's Start Time
sim_time = 0
for task in tasks:
if task not in lastExcStart:
# if no task is running on this core, init the queue with cuurent simTime
lastExcStart[task] = sim_time
class Solution:
def spiral_print(self, matrix):
seen = set()
action_seq = [(0, +1), (+1, 0), (0, -1), (-1, 0)]
act = 0
curr = (0, 0)
seen.add(curr)
res = []
res.append(matrix[curr[0]][curr[1]])
def get_neighbors_4C(self, pt):
# put self.gird in your class private
x,y = pt[0], pt[1]
# x positive top down, Y to the right
maxX = len(self.grid)
maxY = len(self.grid[0])
# define the neighbor pattern
nc4 = '[[x-1,y], [x+1,y], [x,y-1], [x,y+1]]'
#!/usr/bin/env python
import rospy
import tf
from tf import transformations as ts
from geometry_msgs.msg import Transform, Vector3, Quaternion
from geometry_msgs.msg import TransformStamped
from std_msgs.msg import Header
#include <ros/ros.h>
#include <tf2_ros/transform_listener.h>
#include <geometry_msgs/Transform.h>
#include <geometry_msgs/TransformStamped.h>
#include <tf/transform_broadcaster.h>
int main(int argc, char** argv){
ros::init(argc, argv, "fix_tf_cpp");
ros::NodeHandle node;
@codyhex
codyhex / c++ function tittle block.h
Created December 12, 2018 15:08
use this @name so the IDE (Jetbrains) can integrate it.
/**
* @brief Constructor for the wrapper
* @param name The name for this costmap
* @param tf A reference to a TransformListener
*/
@codyhex
codyhex / virtual_table_at_head.cpp
Created November 20, 2017 23:18
virtual_table_at_head created by Hexe - https://repl.it/@Hexe/virtualtableathead
#include <iostream>
struct A
{
int data[2];
A(int x, int y) : data{x, y} {}
virtual void f() {}
};
@codyhex
codyhex / checkBaseClass.cpp
Created November 20, 2017 17:51
checkBaseClass created by Hexe - https://repl.it/@Hexe/checkBaseClass
#include <iostream>
/*
* Class template identification
*/
using namespace std;
template<typename D, typename B>
class IsDerivedFromHelper
{
@codyhex
codyhex / makeCombinations.cpp
Created November 18, 2017 21:56
makeCombinations created by Hexe - https://repl.it/@Hexe/makeCombinations
#include <iostream>
#include <vector>
using namespace std;
/***********************************************/
/* @Task: combination
* @Input: n: number range 1 to n; k is number takes
* @Return: list of lists
* @Example: leetcode 8.5
@codyhex
codyhex / isValidBST.cpp
Created November 15, 2017 17:18
isValidBST created by Hexe - https://repl.it/@Hexe/isValidBST
#include <iostream>
#include <climits>
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x): val(x), left(nullptr), right(nullptr) {}
};