Smart.js IoT platform provides two components for building private smart device infrastructures:
- Firmware for the embedded devices, which is capable of harvesting
// Copyright (c) 2014 Sergey Lyubka. All rights reserved. | |
// Arithmetic expression evaluator. | |
// | |
// Compilation: cc -o eval_arith eval_arith.c | |
// Usage: ./eval_arith "2 - 3 * ( 4 - 2.7 * 11.5 ) + 1.78" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <ctype.h> |
#define END_OF_PARAMS (-1) | |
// Each extensible function is going to have it's own params enum | |
enum { | |
SEND_FILE_EXTRA_HEADER, // next arg is const char * | |
SEND_FILE_BYTE_RANGE, // next args are size_t, size_t | |
SEND_FILE_NUM_PARAMS | |
}; | |
int mg_send_file(const char *path, ...) { |
// Task: user needs to set up a simple HTTP server | |
// Option 1 | |
static void my_handler(struct ns_connection *nc, int ev, void *ev_data) { | |
switch (ev) { | |
case NS_HTTP_REQUEST: | |
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n hi there!! "); | |
nc->flags |= NSF_FINISHED_SENDING_DATA; // Schedule connection close | |
break; | |
default: // We can catch low-level events like NS_RECV, etc |
struct task { | |
socket_t accepted_socket; | |
}; | |
struct queue { | |
struct task tasks[NUM_WORKER_THREADS]; | |
int num_tasks; | |
pthread_mutex_t mutex; | |
pthread_cond_t condvar; | |
}; |
#!/usr/bin/env python | |
# Copyright (c) 2011 by Sergey Lyubka | |
# All rights reserved | |
# | |
# This program calculates note frequencies for chromatic and natural scale. | |
# Chromatic scale is built by splitting an octave (2x frequency bump) onto | |
# 12 equal intervals (semitones). | |
semitones = ['%.5f' % pow(pow(2, x), 1 / 12.0) for x in range(13)] | |
tones = [0, 2, 4, 5, 7, 9, 11] # Major scale |
/* | |
* Large integer manipulation functions. | |
* All integers are assumed to be unsigned and represented as | |
* a contiguous array of bytes (unsigned char *ptr, int len) | |
* in little-endian byte order (ptr points to the least significant byte). | |
*/ | |
#define HUGE 4096 /* Length of the biggest integer in bytes */ | |
/* |
// Usage: | |
// cc -W -Wall ~/tmp/quoted_string_parser.c | |
// ./a.out " dwedewd, dede" " 'sds ee' ,'ddd'" | |
#include <stdio.h> | |
#include <string.h> | |
static const char *whitespaces = " \r\n"; | |
static const char *whitespaces_or_comma = " \r\n,"; |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>GitHub Stars</title> | |
</head> | |
<body> | |
hi | |
</body> | |
</html> |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#define LISTENING_PORT 8000 | |
static void serve_new_connection(FILE *fp) { | |
char method[10], uri[100], protocol[20]; |