Skip to content

Instantly share code, notes, and snippets.

View codyhex's full-sized avatar
🎯
Focusing

He, Peng codyhex

🎯
Focusing
View GitHub Profile
@codyhex
codyhex / foo.js
Created April 19, 2016 14:25 — forked from minshallj/foo.js
roslibjs example
//* The Ros object, wrapping a web socket connection to rosbridge.
var ros = new ROSLIB.Ros({
url: 'ws://localhost:9090' // url to your rosbridge server
});
//* A topic for messaging.
var exampleTopic = new ROSLIB.Topic({
ros: ros,
name: '/com/endpoint/example', // use a sensible namespace
messageType: 'std_msgs/String'
@codyhex
codyhex / readBytesFullArraySize.java
Created January 30, 2017 19:23
Read the bytes from input stream to fill the buffer array size
package com.example;
import java.io.IOException;
import java.util.Arrays;
class MyTestClass
{
public static void main(String[] args){
byte[] bytes = new byte[30];
import java.io.IOException;
import java.util.Arrays;
public class InputStreamExample {
public static void main(String[] args){
byte[] bytes = new byte[30];
try {
System.out.println("Available bytes :"+System.in.available());
# Use 0xFF to AND output the only 8bits for a char.
if cv2.waitKey(0) & 0xFF == ord('q'):
break
@codyhex
codyhex / check_consecutive_ones.cpp
Created September 30, 2017 18:38
checking the max consecutive one sequence in a bitmap array(number)
// https://www.hackerrank.com/challenges/30-binary-numbers/problem
using namespace std;
int main(){
int n;
cin >> n;
int count = 0;
int old = 0;
@codyhex
codyhex / getline_input.py
Created September 30, 2017 19:02
Getting a line input and strip off the heading and tailing spaces.
#!/bin/python3
import sys
if __name__ == "__main__":
n = int(input().strip())
m = int(input().strip())
for a0 in range(m):
x, y, w = input().strip().split(' ')
x, y, w = [int(x), int(y), int(w)]
@codyhex
codyhex / line_input_to_array.py
Last active October 10, 2017 22:42
To get the sum of a line input with the input length.
# Sample Input
# ( you dont need the count number for python)
# 1 2 3 4 10 11
number_of_elements = int(raw_input())
array = map(int, raw_input().split())
print sum(array)
# a nice example where you can use zip to compose pair together to compute them
a_triplet = map(int, input().split())
b_triplet = map(int, input().split())
alice_points = 0
bob_points = 0
for a_val, b_val in zip(a_triplet, b_triplet):
if a_val < b_val:
bob_points += 1
elif a_val > b_val:
using namespace std;
int main() {
int n;
cin >> n;
double pl = 0, mn = 0, zr = 0;
for (int i = 0; i < n; i++) {
int val;
@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) {}
};