Posts

Showing posts from May, 2018

node.js : file upload via express and multer

Image
Form-based File Upload in HTML https://tools.ietf.org/html/rfc1867 Express Fast, unopinionated, minimalist web framework for node. Multer Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. It is written on top of busboy for maximum efficiency. NOTE: Multer will not process any form which is not multipart (multipart/form-data). Client Codes(index.html) <script type="text/javascript"> function upload(postUrl, fieldName, files) { var formData = new FormData(); formData.append(fieldName, files); var req = new XMLHttpRequest(); req.open("POST", postUrl); req.onload = function(event) { console.log(event.target.responseText); }; req.send(formData); } function onchange() { for (let i = 0; i < this.files.length; i++) { upload('/uploads', 'uploadfile', this.files[i]); } } window.onload = function () { var input = document.getElementById('file'); inpu

Print all combination of that select n elements from 1,2,3,...,m.

"C" is for "combination". A combination is an un-ordered collection of distinct elements, usually of a prescribed size and taken from a given set. C(n, r) = n!/[r!(n-r)!]    #include <stdio.h> #include <sys/time.h> int a[1001]; // selected n numbers stored in array a // a[1], a[2], ... , a[n] // a[i+1] > a[i] // a[i] - i <= m - n + 1 void comos(int n, int m) { int i,j; if (n > m) return; for (i = 1; i <= n; i++) { a[i] = i; } int cur = n; do { if (a[cur]-cur <= m - n) { for (i = 1; i <= n; i++) printf("%d ", a[i]); printf("\n"); a[cur]++; continue; } else { if (cur == 1) { break; } a[--cur]++; for (i = 1; i <= (n-cur); i++) a[cur+i] = a[cur] + i; if (a[cur] - cur < m - n + 1) cur=n; } } while(1); } int main() { int N, M; while (scanf("%d %d", &N, &M) != EOF) {

all learning is understanding relationships

James Comer says that no significant learning can occur without a significant relationship. George Washington Carver says all learning is understanding relationships. "You were chosen to be in my class because I am the best teacher and you are the best students, they put us all together so we could show everybody else how to do it." "Really?" "Really. We have to show the other classes how to do it, so when we walk down the hall, people will notice us, so you can't make noise. You just have to strut." "I am somebody. I was somebody when I came. I'll be a better somebody when I leave. I am powerful, and I am strong. I deserve the education that I get here. I have things to do, people to impress, and places to go." "Yeah!" You say it long enough, it starts to be a part of you.

PulseAudio example

PulseAudio APIs pa_simple_new pa_simple_write pa_simple_drain pa_simple_free https://freedesktop.org/software/pulseaudio/doxygen/examples.html build command gcc -o pulse pulse.c `pkg-config --cflags --libs libpulse-simple` source #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <stdio.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <fcntl.h> #include <pulse/simple.h> #include <pulse/error.h> #define BUFSIZE 1024 int main(int argc, char* argv[]) { /* The Sample format to use */ static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 44100, .channels = 2}; pa_simple* s = NULL; int ret = 1; int error; /* replace STDIN with the specified file if needed */ if (argc > 1) { int fd; if ((fd = open(argv[1], O_RDONLY)) < 0) { fprintf(stderr, __FILE__ ": open() failed: %s\n", strerror(errno)); goto finish; } if (dup2(fd, STDIN_

alsa programing example

alsa APIs snd_pcm_open snd_pcm_hw_params_set_format snd_pcm_prepare snd_pcm_writei snd_pcm_drain snd_pcm_close https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html issues If your device can't support mixer feature, or pcm interface can't open multi times. You can try PulseAudio. pulseaudio example compile cmd gcc -o play play.c `pkg-config --cflags --libs alsa` source #include <alsa/asoundlib.h> #include <stdio.h> #define PCM_DEVICE "default" int main(int argc, char** argv) { unsigned int pcm, tmp, dir; int rate, channels, seconds; snd_pcm_t* pcm_handle; snd_pcm_hw_params_t* params; snd_pcm_uframes_t frames; char* buff; int buff_size, loops; if (argc < 4) { printf("Usage: %s <sample_rate> <channels> <seconds>\n", argv[0]); return -1; } rate = atoi(argv[1]); channels = atoi(argv[2]); seconds = atoi(argv[3]); /* Open the PCM device in playback mode */ if