Skip to content

Instantly share code, notes, and snippets.

View Elements-'s full-sized avatar
:atom:
Focusing

Cameron Kelliher Elements-

:atom:
Focusing
View GitHub Profile
@Elements-
Elements- / getMP4Length.js
Created March 26, 2016 18:32
Read the duration of a mp4 file nodejs
var buff = new Buffer(100);
fs.open(file, 'r', function(err, fd) {
fs.read(fd, buff, 0, 100, 0, function(err, bytesRead, buffer) {
var start = buffer.indexOf(new Buffer('mvhd')) + 17;
var timeScale = buffer.readUInt32BE(start, 4);
var duration = buffer.readUInt32BE(start + 4, 4);
var movieLength = Math.floor(duration/timeScale);
console.log('time scale: ' + timeScale);
console.log('duration: ' + duration);
@Elements-
Elements- / pngHeaderInformation.js
Created November 14, 2015 03:40
Get PNG header information from an image (width, height, bit depth, and color type)
var fs = require('fs');
fs.readFile('test.png', function (err, data) {
var pngHeader = new Buffer([137, 80, 78, 71, 13, 10, 26, 10]);
var header = data.slice(0, 8);
if(header.compare(pngHeader) != 0) {
console.log('Invalid png file header!')
process.exit();
}
var fileHeader = {
@Elements-
Elements- / DoubleChestCheck
Created December 6, 2014 02:58
Check if a chest block is a double or single then get the inventory(s)
Block b = ....
BlockFace[] sides = new BlockFace[] {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
for(BlockFace bf : sides) {
if(b.getRelative(bf, 1).getType() == b.getType()) {
Inventory left = ((DoubleChestInventory)((InventoryHolder)b.getState()).getInventory()).getLeftSide();
Inventory right = ((DoubleChestInventory)((InventoryHolder)b.getState()).getInventory()).getRightSide();