Skip to content

Instantly share code, notes, and snippets.

View grimmerk's full-sized avatar
🌖

Grimmer Kang grimmerk

🌖
View GitHub Profile
@grimmerk
grimmerk / first.ipynb
Last active May 28, 2018 06:12
charts
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@grimmerk
grimmerk / stringToUTF8ParseFile.js
Last active April 8, 2018 15:42
In Node.js, save JavaScript String as a UTF-8 encoding file in Parse.File system (parseplatform)
const e = require('text-encoding'); //it is built-in for some browsers. We neeed to install it in Node.js
const uint8array = new e.TextEncoder().encode(stringData);
const normalArray = Array.prototype.slice.call(uint8array);
// http://docs.parseplatform.org/js/guide/#creating-a-parsefile
const file = new Parse.File(fileName, normalArray);
file.save().then(function() {
// The file has been saved to Parse.
}, function(error) {
// The file either could not be read, or could not be saved to Parse.
@grimmerk
grimmerk / lambda.js
Last active December 17, 2017 08:30
AWS lambda example to write/read, ref: https://stackoverflow.com/a/35007461/7354486
// ref: https://stackoverflow.com/a/35007461/7354486
var tester = require("./test.js");
console.log("test2");
console.log("first line2");
exports.handler3 = (event, context, callback) => {
console.log("event2:", event);
tester.test5();
// TODO implement
@grimmerk
grimmerk / read.c
Created November 17, 2017 08:42
linux/unix use c to read file
// #include <error.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <time.h>
// forked process can use the file descriptor from parent's process without open again. Then two process can synchronize the file operations.
// ref:
// https://stackoverflow.com/questions/5284062/two-file-descriptors-to-same-file
@grimmerk
grimmerk / qt_websocket_example.cpp
Last active November 17, 2017 08:43
qtwebsocket
// not use now
// uWebSockets part, comment now, change to use qt's built-in WebSocket
//TODO Grimmer: this is for new CARTA, and is using hacked way to workaround passing command/object id/callback issue.
// void SessionDispatcher::startWebSocketServer() {
// std::cout << "websocket starts running" << std::endl;
// uWS::Hub h;
// // DesktopConnector *conn = this;
// h.onMessage([this](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode) {
@grimmerk
grimmerk / localStorage.js
Created October 3, 2016 18:50 — forked from anhang/localStorage.js
HTML5 Local Storage with Expiration
AZHU.storage = {
save : function(key, jsonData, expirationMin){
if (!Modernizr.localstorage){return false;}
var expirationMS = expirationMin * 60 * 1000;
var record = {value: JSON.stringify(jsonData), timestamp: new Date().getTime() + expirationMS}
localStorage.setItem(key, JSON.stringify(record));
return jsonData;
},
load : function(key){
if (!Modernizr.localstorage){return false;}