Skip to content

Instantly share code, notes, and snippets.

View kitsook's full-sized avatar

Clarence K.C. Ho kitsook

View GitHub Profile
package net.clarenceho.util;
import java.util.function.UnaryOperator;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* Given equation y = f(x), find successively better approximations to the roots
* (or zeroes) of a real-valued function (i.e. find x where y = 0)
* <p>
package net.clarenceho.util;
import static org.junit.Assert.*;
import org.junit.Test;
import java.math.BigDecimal;
public class TestNewton {
@Test
#!/usr/bin/env python
# Testing I2C on Raspbery Pi
# Send a byte to slave and request a byte back
#
# Created by Clarence Ho 2015
import smbus
import time
# for RPI rev 1...
long long perfectSquare(long long num)
{
// obvious cases
int lastDigit = num % 10;
if (num <= 0 || lastDigit == 2 || lastDigit == 3 || lastDigit == 7 || lastDigit == 8)
{
return 0;
}
long long section = 1;
package net.clarenceho.test;
public class FizzBuzz {
public static String doFizzBuzz1(int i) {
StringBuilder sb = new StringBuilder();
if (i % 3 == 0) {
sb.append("Fizz");
}
if (i % 5 == 0) {
@kitsook
kitsook / SConscript
Last active June 23, 2020 21:21
SConscript for compiling v8 engine under MongoDB 3.0.x source tree
# Copyright 2012 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
@kitsook
kitsook / detect.py
Created January 1, 2017 06:32
Face detection with OpenCV
import cv2
import numpy as np
cv2.namedWindow("camera", 1)
capture = cv2.VideoCapture(0)
# Set to None to use default size
# To improve performance, can specify a lower resolution. e.g. 320x240
width = 320
height = 240
@kitsook
kitsook / FibonacciNum.java
Last active June 18, 2017 17:04
TriFib - A Java stream approach on testing triangular Fibonacci numbers
package net.clarenceho.TriFib;
import java.util.stream.Stream;
import java.math.BigInteger;
public class FibonacciNum {
/**
* Stream of Fibonacci number in BigInteger
* @return stream of Fibonacci number
@kitsook
kitsook / cpuinfo.txt
Created March 26, 2019 03:57
Jetson Nano cpuinfo
~$ cat /proc/cpuinfo
processor : 0
model name : ARMv8 Processor rev 1 (v8l)
BogoMIPS : 38.40
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 1
@kitsook
kitsook / dmesg.txt
Created March 26, 2019 04:01
Jetson Nano
~$ dmesg
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.9.140-tegra (buildbrain@mobile-u64-3531) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05) ) #1 SMP PREEMPT Wed Mar 13 00:32:22 PDT 2019
[ 0.000000] Boot CPU: AArch64 Processor [411fd071]
[ 0.000000] OF: fdt:memory scan node memory@80000000, reg size 48,
[ 0.000000] OF: fdt: - 80000000 , 7ee00000
[ 0.000000] OF: fdt: - 100000000 , 7f200000
[ 0.000000] Found tegra_fbmem: 00800000@92cb6000
[ 0.000000] OF: fdt:Reserved memory: failed to reserve memory for node 'fb0_carveout': base 0x0000000000000000, size 0 MiB
[ 0.000000] OF: fdt:Reserved memory: failed to reserve memory for node 'fb0_carveout': base 0x0000000000000000, size 0 MiB