Skip to content

Instantly share code, notes, and snippets.

View welll's full-sized avatar
🏠
Working from home

Wellington Soares welll

🏠
Working from home
View GitHub Profile
@welll
welll / gist:7f7fa578d0539ed5c275
Last active August 29, 2015 14:11
NodeJS - Function to Replace a Text Block
/*
* This function will replace the content inside
* the commentary "setupVars"
*
* Param:
* content: the input string, e.g, a entire HTML file
* data: snippet to be included
*
* <html>
* <body>
@welll
welll / gist:e8f4e2bcce66332663a2
Last active August 29, 2015 14:11
Using typedef to function
typedef int myinterger;
typedef int (*fn_adder)(int, long);
int sum(int a, long b){
return a+b;
}
@welll
welll / throttle.js
Created December 13, 2014 21:52
Javascript - Throttle Function
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
@welll
welll / const.cpp
Created December 14, 2014 01:39
C++ - Const
void Foo( int * ptr,
int const * ptrToConst,
int * const constPtr,
int const * const constPtrToConst )
{
*ptr = 0; // OK: modifies the "pointee" data
ptr = NULL; // OK: modifies the pointer
*ptrToConst = 0; // Error! Cannot modify the "pointee" data
ptrToConst = NULL; // OK: modifies the pointer
@welll
welll / gist:0fc2a1285d2b196f9481
Last active January 20, 2016 16:56
C++ - namespace
using namespace foo; //generic, the same behaviour in Java, include com.foo.*
using bar;// specific, the same behaviour in Java, include com.package.bar;
http://stackoverflow.com/questions/2898316/using-a-member-function-pointer-within-a-class
//char *buffer = new char[bufferSize];
std::string buffer;
buffer.resize(bufferSize);
@welll
welll / date_conversion.cpp
Created January 28, 2016 11:58 — forked from st-j/date_conversion.cpp
Convert between boost dates and Unix timestamps (time_t)
#include <ctime>
#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
//==============================================================================
//! Convert date part of Unix timestamp (time_t) to boost date
//!
@welll
welll / json_with_cpp.cpp
Created July 22, 2016 16:43 — forked from makomweb/json_with_cpp.cpp
Some fun with JSON serialization/deserialization using C++ REST SDK (Codename "Casablanca").
#include <cpprest/json.h>
#include <sstream>
using namespace std;
typedef web::json::value JsonValue;
typedef web::json::value::value_type JsonValueType;
typedef std::wstring String;
typedef std::wstringstream StringStream;
String JsonValueTypeToString(const JsonValueType& type)
@welll
welll / make-animated-gif.js
Created October 13, 2016 14:56 — forked from AVGP/make-animated-gif.js
Uses three.js, three-software-renderer & omggif to render an animated GIF from a Three.js Scene on the server with node.js
var fs = require('fs'),
omggif = require('omggif'),
THREE = require('three'),
SoftwareRenderer = require('three-software-renderer');
// How many frames and how large shall the GIF be?
var NUM_FRAMES = 200, WIDTH = 500, HEIGHT = 500;
// Our scene, camera and renderer and a box to render
var scene = new THREE.Scene(),
@welll
welll / enum-access.js
Created November 1, 2016 02:48 — forked from bnoguchi/enum-access.js
How to access enumValues in mongoose from a Model or Document
var mongoose = require('./index')
, TempSchema = new mongoose.Schema({
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']}
});
var Temp = mongoose.model('Temp', TempSchema);
console.log(Temp.schema.path('salutation').enumValues);
var temp = new Temp();
console.log(temp.schema.path('salutation').enumValues);