Skip to content

Instantly share code, notes, and snippets.

View gabrielstuff's full-sized avatar

Gabriel gabrielstuff

View GitHub Profile
@gabrielstuff
gabrielstuff / ffmpeg.js
Created March 12, 2015 21:39
FSCollection.js
function generatePreview(fileObj, readStream, writeStream) {
fileObj.name('preview.jpg', {
store: 'thumbs'
});
fileObj.extension('jpg', {
store: 'thumbs'
});
fileObj.type('image/jpg', {
store: 'thumbs'
});
db['cfs.medias.filerecord'].aggregate(
[
{
$project:
{
year: { $year: "$uploadedAt" },
month: { $month: "$uploadedAt" },
day: { $dayOfMonth: "$uploadedAt" },
hour: { $hour: "$uploadedAt" },
minutes: { $minute: "$uploadedAt" },
@gabrielstuff
gabrielstuff / rename.js
Created January 17, 2015 02:29
Rename a file by incrementing its number
var fs = require('fs'),
schedule = require('node-schedule'),
currentfilename = '/Users/gabrielstuff/Desktop/default/iehg',
newFilename = '/Users/gabrielstuff/Desktop/default/video',
extension = 'mp4',
number = 0;
function rename() {
fs.rename(currentfilename+'.' + extension, newFilename + '_' + number + '.' + extension, function(err) {
if (err) {
@gabrielstuff
gabrielstuff / ffmpeg.js
Last active August 29, 2015 14:13
ffmeg nodejs
var fs = require('fs'),
videoName = './record_10.mp4',
child_process = require("child_process"),
exec = child_process.exec;
/*This works like a charm*/
var ffmpeg = child_process.spawn("ffmpeg", [
'-i', videoName, // path
'-vf', 'thumbnail,scale=640:360',
'-r', '1',
@gabrielstuff
gabrielstuff / post_data.js
Created September 12, 2014 22:27
async Meteorjs
Router.map(function() {
this.route('messages', {
path: '/api/messages',
where: 'server',
action: function() {
xml2js = Meteor.npmRequire('xml2js');
// GET, POST, PUT, DELETE
var req = this.request;
var res = this.response;
@gabrielstuff
gabrielstuff / getCanvasUrl.js
Created March 7, 2014 10:26
Canvas to webkit url without crashing your browser see references : https://code.google.com/p/chromium/issues/detail?id=69227
function getCanvasURL(canvas){
var parts = canvas.toDataURL().match(/data:([^;]*)(;base64)?,([0-9A-Za-z+/]+)/);
//assume base64 encoding
var binStr = atob(parts[3]);
//convert to binary in ArrayBuffer
var buf = new ArrayBuffer(binStr.length);
var view = new Uint8Array(buf);
for (var i = 0; i < view.length; i++)
@gabrielstuff
gabrielstuff / rec_check.php
Created February 25, 2014 00:37
Recursive check php
private function recursiveCheck($array)
{
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $key => $current) {
$keyValid = array('section', 'block', 'text', 'item');
if(in_array($key, $keyValid) && $key !== 0 && $this->is_assoc($current)){
//error_log('key: '.$key);
$prevValue = $iterator->getInnerIterator()->offsetGet( $key );
$iterator->getInnerIterator()->offsetUnset($key);
@gabrielstuff
gabrielstuff / future_meteor_event.js
Created January 22, 2014 22:20
Deal with event and future
Meteor.methods({
'imapConnect': function(email, password) {
var fut = new Future(),
imap = new Imap({
user: email,
password: password,
host: host,
port: port,
tls: tls,
@gabrielstuff
gabrielstuff / client.js
Last active January 3, 2016 11:49
Meteor AWS using aws smart package, npm smart package and native request from npm module request.
Meteor.call('getFile', 'ksxxxx.domain.com', 80, '/path/last.gif', function(res, err){
console.log('YEAH: '+res);
});
@gabrielstuff
gabrielstuff / 0_reuse_code.js
Created October 18, 2013 08:49
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