Skip to content

Instantly share code, notes, and snippets.

@CaptainJH
CaptainJH / 0_reuse_code.js
Created March 21, 2014 14:39
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@CaptainJH
CaptainJH / Utils.r
Created March 24, 2014 02:39
Get content from a HTML page
library(RCurl)
library(stringr)
RootURL <- "http://10.130.19.139/19659/"
DatFileURLs <- c()
CheckDatFolder <- function(folder)
{
URL <- sprintf("%s%s/", RootURL, folder)
@CaptainJH
CaptainJH / RemoveRedundantMail.md
Last active August 29, 2015 13:57
AppleScript Samples

先还是要称赞一下 Apple 的 Mail,比Windows 的 Live Mail 要强太多了:+1:。之前我只是简单的输入了一下Google Apps的账号信息,它就能替我同步邮件了,甚至我都没有在Google Apps 中enable 它的 smtp 和 imtp,太神奇了。而到了Live Mail 这边,就不行了,必须一步一步设置,甚至连端口号,都得我从网上去查。但是这样一来,就带了一点麻烦,因为之前 Mail 已经为我同步了邮件,enable Google Apps 的 smtp 和 imtp 之后,它又替我把每一封邮件重复下载了一遍。还好,我用下面这段 AppleScript 把重复的邮件都删除了,非常好的练手机会。

@CaptainJH
CaptainJH / UserStatistic.r
Created March 24, 2014 06:31
主要是统计用户上传信息的 r 代码
ReadUserInfoFunc <- function(file)
{
#print(file)
ret <- read.table(file, header=TRUE, sep=",")
return (ret)
}
SplitIntoBox <- function(num, split)
{
@CaptainJH
CaptainJH / R_Graph.r
Created March 24, 2014 07:41
R 的一些基本画图功能
lx = c(1:9)
ly = c(10:18)
#pdf 的单位应该是inch
#pdf("D:/firstpdf.pdf", width=100, height=10)
# png 的单位是像素
png("D:/firstpng.png", width=640, height=1280)
opar <- par(no.readonly = TRUE)
par(mfrow=c(3, 1))
@CaptainJH
CaptainJH / ChromiumEmbedded.cpp
Last active August 29, 2015 13:57
How to setup a bare bone chromium windows app
// ChromiumEmbedded_test.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <assert.h>
#include "ChromiumEmbedded_test.h"
#include "include\cef_app.h"
#include "bareboneshandler.h"
@CaptainJH
CaptainJH / cairo_snippet.cpp
Last active August 29, 2015 13:57
some cairo code snippet in cinder
// draw window background
// before this ctx should be created first in every rendering frame, like this:
// cairo::Context ctx(cario::createWindowSurface())
void renderScene(cairo::Contect& ctx)
{
// clear the context with our radial gradient
cairo::GradientRadial radialGrad( getWindowCenter(), 0, getWindowCenter(), getWindowWidth() );
radialGrad.addColorStop( 0, Color( 1, 1, 1 ) );
radialGrad.addColorStop( 1, Color( 0.6, 0.6, 0.6 ) );
@CaptainJH
CaptainJH / read_file_line_by_line.cpp
Last active August 29, 2015 13:59
Read all the files in certain folder and parse the files
bool getline(FILE* f, std::string& line)
{
line.clear();
char c = 0;
do {
c = fgetc(f);
if (c == EOF)
@CaptainJH
CaptainJH / Iterate days
Last active August 17, 2023 09:42
Output date string in C++
/// iterate from fromD(like "2014-04-02") to toD("2014-05-02")
std::string tpStr = fromD;
do {
//std::cout << tpStr << std::endl;
ParseIntoUserInfoDB(tpStr, root, order);
std::tm tm;
std::stringstream ss(tpStr + " 0:0:1");
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));
@CaptainJH
CaptainJH / routine.sh
Last active August 29, 2015 14:00
parse webpage then download file, the decompress them
#!/bin/bash
echo "=======ExportUserReport bash==========="
Root="http://10.130.19.139/19659/"
Root2="http://10.164.7.76/19659/"
DateBegin=$1
TargetRoot="F:/UserReport/"
d=$DateBegin
while true; do
echo $d