Skip to content

Instantly share code, notes, and snippets.

@4poc
4poc / gist:9c67a8ff27b429559986
Created September 19, 2014 00:49
Simplex noise in D (ported from java, DLang)
/**
* Simplex noise algorithm.
*
* This is a port of the public domain java implementation (see
* original header) and is public domain aswell.
* ported by Matthias Hecker <apoc.cc>.
* Links:
* http://webstaff.itn.liu.se/~stegu/simplexnoise/
* http://stackoverflow.com/a/18516731
*/
@4poc
4poc / gist:5d90091db803f52b618d
Last active August 29, 2015 14:03
GO IRC Bot
package main
import (
"bufio"
"crypto/tls"
"fmt"
"io"
"net"
"reflect"
"regexp"
@4poc
4poc / gist:c279d24157af06d12cbe
Last active June 23, 2022 09:53
GOZORK Text Adventure Game
/**
* GOZORK Text Adventure Game
* by apoc <http://apoc.cc>
*
* Inspired by the infamous beginning of Zork I.
* Reading the source will obviously spoil the game.
* The goal is to somehow kill the troll.
* Oh yeah and: This is my first GO program! Which would be
* my perfect excuse for the bad code quality1!
* Here is a solution/transcript:
@4poc
4poc / gist:10953895
Created April 17, 2014 04:57
Use reflection to invoke callbacks in mixins that use metadata as annotation.
@MirrorsUsed(symbols: '', override: '*')
import 'dart:mirrors';
class ReflectionHelper {
static callMethodsByAnnotation(var object, var symbol) {
var mirror = reflectClass(object.runtimeType);
mirror.instanceMembers.forEach((name, method) {
for (var metadata in method.metadata)
if (metadata.hasReflectee && metadata.reflectee == symbol)
reflect(object).invoke(name, []);
@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)
@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: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: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: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:6281388
Last active July 1, 2021 13:53
Minecraft supports querying the MOTD, player count, max players and server version via the usual port, this ruby class implements this. Works with ruby >= 1.9.3/2.0.0
require 'socket'
##
# Pings a minecraft server and returns motd and playercount.
# Works with ruby >=1.9.3/2.0.0
#
# More information and sample code here:
# http://wiki.vg/Server_List_Ping
##
class MinecraftPing