Instantly share code, notes, and snippets.

View gist:9c67a8ff27b429559986
/**
* 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
*/
View gist:5d90091db803f52b618d
package main
import (
"bufio"
"crypto/tls"
"fmt"
"io"
"net"
"reflect"
"regexp"
View gist:c279d24157af06d12cbe
/**
* 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:
View gist:10953895
@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, []);
View gist:7716437
(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)
View gist:6840150
> TypeError: can't compare offset-naive and offset-aware datetimes
channel.published_at = dateutil.parser.parse(snippet['publishedAt'], ignoretz=True)
^^^^^^^^^^^^^
View gist:6598991

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 => true)

View gist:6575746
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
View gist:6565551
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
View gist:6281388
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