Skip to content

Instantly share code, notes, and snippets.

#define VOMIT_ON_FAILURE(a) do { if (0 != (a)) { VOMIT_ABORT(errno, #a); } } while (0)
#define VOMIT_ON_FAILURE_NO_ERRNO(a) do { int err = (a); if (0 != err) { VOMIT_ABORT(err, #a); } } while (0)
#define VOMIT_ABORT(err, str) do { int code = (err); fprintf(stderr, "%s failed on line %d in file %s: %d (%s)\n", str, __LINE__, __FILE__, code, strerror(code)); abort(); } while(0)
@cloudrain21
cloudrain21 / rtf.cpp
Last active January 16, 2016 03:30
recovery test framework
#include "rth.h"
#ifdef _RTF_TEST
cmnRTFInfo gTestCaseMap[MAX_RTF_HASH];
static int cmnRTFGetHashVal ( const char* aTestString , int aStrLen )
{
int i;
unsigned int sKey = 0;
@cloudrain21
cloudrain21 / gist:04d3bd795d46e5f811af
Created February 4, 2016 01:57
use variable name as another variable's name
# use variable name as another variable's name
foobar="xx"
name=foobar
echo ${!name}
@cloudrain21
cloudrain21 / gulpfile.js
Created March 19, 2016 17:26
gulpfile.js : auto restart & livereload the server with gulp
// webserver 모듈은 public 아래의 contents 를 기준으로
// gulp 기동과 동시에 webserver 및 explorer 까지 띄워준다.
// gulp-livereload 모듈은 sublime-text 의 LiveReload
// 플러그인을 Enable 시키는데 이 때 400 ms 의 delay 를 주면서
// chrome 의 live reload extension 과 통신하여 refresh 하게 한다.
var gulp = require('gulp'),
// jshint = require('gulp-jshint'),
sass = require('gulp-ruby-sass'),
@cloudrain21
cloudrain21 / gulpfile.js
Created March 19, 2016 17:28
gulpfile.js : auto restart & livereload the server with gulp (my 2nd)
'use strict';
var gulp = require( 'gulp' ),
gutil = require( 'gulp-util' ),
fork = require( 'child_process' ).fork,
tinyLr = require( 'tiny-lr' ),
sass = require( 'gulp-ruby-sass' ),
sourcemaps = require('gulp-sourcemaps'),
async = require( 'async' );
@cloudrain21
cloudrain21 / imagegrid_mixin.scss
Created March 20, 2016 02:49
sass mixins for image grid
$roundness: 20px 0 20px 0;
@mixin clearfix {
&:before,
&:after {
content: '';
display: table;
}
&:after {
clear: both;
@cloudrain21
cloudrain21 / serialized_parallelized_callback.js
Last active April 8, 2016 23:10
Use serialized or parallelized callback in nodejs
// prints text and waits one second
function doSomethingAsync(callback) {
console.log('doSomethingAsync: Wait for one second.');
setTimeout(function() { callback(); }, 1000);
}
// prints text and waits half a second
function doSomethingElseAsync(callback) {
console.log('doSomethingElseAsync: Wait for half a sec.');
setTimeout(function() { callback(); }, 500);
@cloudrain21
cloudrain21 / fileinfo.js
Last active April 10, 2016 09:31
Simple file stat infomation module
var fs = require('fs'),
util = require('util'),
imgsize = require('image-size');
module.exports = (function(){
var supportExt = ["jpg", "jpeg", "png"]; // supported extension array
var dirPath = ""; // directory path
var fileList = []; // file name array
var fileInfo = [{}]; // array of file info object
@cloudrain21
cloudrain21 / mongodb.js
Created April 10, 2016 09:35
Simple mongodb module
var mongoose = require('mongoose'),
Schema = require('mongoose').Schema;
module.exports = (function() {
var defaultUrl = "mongodb://localhost:27017/test";
var url = defaultUrl;
var schemaName = null;
var schemaDef = null;
var docuModel;
@cloudrain21
cloudrain21 / extract_filename_frompath.js
Created April 11, 2016 21:15
Extract filename only from path
var fileName = fPath.match(/[-_\w]+[.][\w]+$/i)[0];
var fileName = fPath.split('/').pop();