Skip to content

Instantly share code, notes, and snippets.

@4poc
4poc / gist:4236849
Created December 7, 2012 21:57
Playing around with computercraft turtles
-- Stack (for Lua 5.1)#http://snippets.luacode.org/snippets/stack_97
function NewStack(t)
local Stack = {
push = function(self, ...)
for _, v in ipairs{...} do
self[#self+1] = v
end
end,
pop = function(self, num)
@4poc
4poc / LOLActivity.java
Created December 1, 2012 23:58
LOLActivity.java
final AssetBitmapTextureAtlasSource sourceAtlas = AssetBitmapTextureAtlasSource.create(getAssets(), path);
int width = sourceAtlas.getTextureWidth();
int height = sourceAtlas.getTextureHeight();
BitmapTextureAtlas atlas = new BitmapTextureAtlas(getTextureManager(), width, height);
TiledTextureRegion texture = BitmapTextureAtlasTextureRegionFactory.createTiledFromSource(
atlas,
new ColorKeyBitmapTextureAtlasSourceDecorator(sourceAtlas, RectangleBitmapTextureAtlasSourceDecoratorShape
.getDefaultInstance(), android.graphics.Color.rgb(255, 0, 255)), 0, 0, width / tileWidth, height / tileHeight);
@4poc
4poc / gist:3155832
Created July 21, 2012 13:30
C++11 Callbacks with function and lambda
#include <iostream>
#include <vector>
#include <functional>
class WorkingClass {
public:
typedef const std::function<void (int)> handler_t;
void AddHandler(handler_t& h) {
handlerList.push_back(&h);
}
@4poc
4poc / gist:3155033
Created July 21, 2012 07:56
C++11 variadic template printf with boost::format
#include <boost/format.hpp>
void LogMessage(boost::format& message) {
std::cout << message.str() << std::endl;
}
template<typename TValue, typename... TArgs>
void LogMessage(boost::format& message, TValue arg, TArgs... args) {
message % arg;
LogMessage(message, args...);
@4poc
4poc / cp437.hpp
Created July 12, 2012 01:16
Code page 437
/*
Code page 437 is the charset used by the original IBM PC,
it includes a wide variety of graphical symbols for ascii
drawings.
In this implementation I define unicode code points that
match the original cp437 symbols. The table also includes
the unique character name and if available the 7-bit
US-ASCII character.
@4poc
4poc / const pointer.cc
Created July 2, 2012 17:37
random c++ stuff
int main(int argc, char **argv) {
int num = 42;
// marks value the ptr is refering as constant
const int *p1 = &num;
// (*p1)++; // illegal
p1++; // legal
///////////////////////////////////////////////////
@4poc
4poc / GalleryAdapter.java
Created March 1, 2012 22:11
GalleryAdapter.java
public void onNewItems(List<Item> newItems) {
notifyDataSetChanged();
} //just a test
@4poc
4poc / gist:1565186
Created January 5, 2012 13:06
ffmpeg / mpeg-ts / m3u8 / HLS
ffmpeg \
-i INPUT_FILE \
-re \
-r 23.976 \
-s 480x204 \
-aspect 2.35 \
-acodec libfaac \
-ac 2 \
-ar 44100 \
-ab 128k \
@4poc
4poc / LimitStream.js
Created December 10, 2011 03:41
Node.js: LimitStream (Bandwidth limited Readable+Writable Stream)
var fs = require('fs'),
util = require('util'),
Stream = require('stream').Stream;
/**
* Create a bandwidth limited stream
*
* This is a read+writeable stream that can limit how fast it
* is written onto by emitting pause and resume events to
* maintain a specified bandwidth limit, that limit can
@4poc
4poc / vimrc_stop_using_arrow_keys
Created March 11, 2011 08:46
Learning vim, try to stop using the arrow keys ;)
" stop using arrow keys!
map <UP> d'oh!
map <DOWN> d'oh!
map <LEFT> d'oh!
map <RIGHT> d'oh!
imap <UP> d'oh!
imap <DOWN> d'oh!
imap <LEFT> d'oh!
imap <RIGHT> d'oh!