Skip to content

Instantly share code, notes, and snippets.

@gnitnaw
gnitnaw / prime.c
Last active August 29, 2015 14:21
Search prime number in 0~N
#include <sys/time.h> // timer
#include <stdio.h> // printf
#include <stdlib.h> // malloc, free
#include <stdbool.h> // bool
const int N = 1000000; // Range of Prime
const int nTest = 2; // Two test
struct Measurement {
int nPrime; // number of Primes
@gnitnaw
gnitnaw / BigNumber.cpp
Last active August 29, 2015 14:21
Class to estimate extra long number
#include <vector>
#include <iostream>
#include <sstream>
#include <math.h>
#include <sys/time.h>
using namespace std;
class BigNumber {
private :
@gnitnaw
gnitnaw / Simpson.c
Created May 25, 2015 17:45
Integral with Simpson's_rule
#include <stdio.h> // printf
#include <math.h> // sin, atan
double simpson(double a, double b, double (*func)(double)); // Simpson's_rule
double integral(double xi, double xf, int n, double (*func)(double)); // Integral with some tools
int main() {
double pi = 4.0*atan(1.0);
double surface;
for (int i=10; i<=50; i+=2) {
@gnitnaw
gnitnaw / strcomp.c
Last active August 29, 2015 14:22
compare two strings
#include <stdio.h>
#define MAXSIZE 80
void strcomp(char* p1, char* p2);
void read_string(char *pt);
int main(void)
{
char line1[MAXSIZE]="", line2[MAXSIZE]="";
printf("Enter first string : ");
//fgets(line1, sizeof(line1), stdin);
@gnitnaw
gnitnaw / char.c
Created June 10, 2015 13:30
fflush use?
#include <stdio.h>
#define MAXSIZE 256
void read_string(char* p);
int main(void) {
char c, s[MAXSIZE];
puts("I/O lib");
puts("");
@gnitnaw
gnitnaw / chars.c
Last active August 29, 2015 14:22
char separate
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 256
#define NITEM 15
int getData(char* line, char** t);
void outputResult(FILE *fout, char** title, char** t, int N);
int main(void) {
char s;
@gnitnaw
gnitnaw / LED.c
Last active June 28, 2022 05:32
module to control 3 LED
/*
* kernel module for LED
*
* Author:
* Wan-Ting CHEN (wanting@gmail.com)
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
@gnitnaw
gnitnaw / Makefile
Created June 29, 2015 12:15
DHT11 driver
obj-m += dht11.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
@gnitnaw
gnitnaw / mcp320x.dts
Last active November 5, 2015 17:38
Device tree overlay for mcp3008
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708";
/* disable spi-dev for spi0.0 */
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
@gnitnaw
gnitnaw / mpu6050.dts
Created July 20, 2015 14:25
Device tree overlay for mpu6050
// Definitions for MPU6050
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2708";
fragment@0 {
target = <&i2c1>;
__overlay__ {