Skip to content

Instantly share code, notes, and snippets.

@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 = #
// (*p1)++; // illegal
p1++; // legal
///////////////////////////////////////////////////
@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 / 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: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)
foo = {
'nested': {
'dict': 42
}
}
query = 'nested.dict'
# reduce:
from functools import reduce
@4poc
4poc / gist:6565551
Created September 14, 2013 20:54
mechanize moneypatch: extend cookie_jar to allow to import/export cookies as strings
class Mechanize::CookieJar
public
def save_str
s = StringIO.new
save(s, :cookiestxt, :session => true)
s.string
end
def load_str(str)
s = StringIO.new str
@4poc
4poc / gist:6575746
Created September 16, 2013 01:18
Implements a rbot plugin that waits for user input using fibers, just a simple example to show the concept.
class FiberPlugin < Plugin
def fiber(m, params)
# imagine this beeing a long (possible infinite) list of something, that is loaded on request
data = ('a'...'z').to_a
@fiber = Fiber.new do
data.each_slice(3) do |partial|
m.reply partial.join(', ') + " #{Underline}Type &more for more data."
Fiber.yield
end
@4poc
4poc / gist:6598991
Last active December 23, 2015 07:09
Implements a fiber extension for rbot plugins, adds a wait_for() functionality.

Fiber Extension for rbot plugins

This extension can be included in Plugin classes, works only with ruby >= 1.9.3/2.0.0. Does currently not work with threads unfortunately :(

It does extend it with the following:

  • adds a :fiber => true option to map/map! command mappings, this envelops each call to the command action/method in a new Fiber block

  • adds a new wait_for method that can be called from commands (that are mapped with :fiber =&gt; true)

@4poc
4poc / gist:6840150
Created October 5, 2013 12:13
SQLAlchemy Session Error: Timezone/Datetime related
> TypeError: can't compare offset-naive and offset-aware datetimes
channel.published_at = dateutil.parser.parse(snippet['publishedAt'], ignoretz=True)
^^^^^^^^^^^^^
@4poc
4poc / gist:7716437
Last active December 29, 2015 19:19
Simple Example IRC Bot, my first clojure program!
(ns cljbot
(:use [clojure.string :only (split join)]
[clojure.pprint :only (pprint)])
(:import (javax.net.ssl SSLSocketFactory X509TrustManager SSLContext TrustManager)
(java.io BufferedReader PrintWriter InputStreamReader)
(java.security SecureRandom)
(java.util.regex Pattern)))
(def HOST "irc.teranetworks.de")
(def PORT 6697)