Skip to content

Instantly share code, notes, and snippets.

View Mononofu's full-sized avatar

Julian Schrittwieser Mononofu

View GitHub Profile
@Mononofu
Mononofu / back.html
Created June 10, 2014 13:37
Dynamic Anki cards
{{FrontSide}}
<hr id="answer">
<span class="replace-back">{{Back}}</span>
<script>
try {
_ref = $('.replace-back');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@Mononofu
Mononofu / minimal.c
Created March 9, 2012 20:34
Minimal xscreensaver
/* xscreensaver, Copyright (c) 1992-2008 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
@Mononofu
Mononofu / sort.py
Created March 18, 2012 20:09
algodat sort
import random
def sort(a, feedback=False):
lower_limit = 0
upper_limit = len(a) - 1
steps = 0
while(lower_limit != upper_limit ):
i = lower_limit
while i < upper_limit - 1:
@Mononofu
Mononofu / oauth.scala
Created September 3, 2012 14:22
Use OAuth 2 with App Engine by requesting a cookie
// this is kind of a hack since App Engine doesn't support OAuth 2, but that's the
// only version of OAuth that's natively supported by Android
val token = settings.getString("oauth2_token", "")
// send OAuth token to appspot login page
// response will contain a valid cookie
val req = new HttpGet("https://x-allow-oauth-dot-google-showy.appspot.com/_ah/login?continue=http://localhost/&auth=" + token);
val client = new DefaultHttpClient()
// avoid redirects - we are only interested in the cookie, not any content
client.getParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false)
// we are not interested in the result, so no need to save it
@Mononofu
Mononofu / gist:4145742
Created November 25, 2012 22:49
Straight-Forward sudoku solver
:- initialization(solve).
solve :- sudoku([_, _, 1, _, _, _, 8, _, _,
_, 7, _, 3, 1, _, _, 9, _,
3, _, _, _, 4, 5, _, _, 7,
_, 9, _, 7, _, _, 5, _, _,
_, 4, 2, _, 5, _, 1, 3, _,
_, _, 3, _, _, 9, _, 4, _,
2, _, _, 5, 7, _, _, _, 4,
_, 3, _, _, 9, 1, _, 6, _,
@Mononofu
Mononofu / build.sbt
Created February 21, 2013 09:21
Fails to compile with: /home/mononofu/tmp/minimal/minimal.scala:7: erroneous or inaccessible type [error] def plus(x: Measure[T],y: Measure[T]): Measure[T] = x + y
scalaVersion in ThisBuild := "2.10.0"
scalacOptions in ThisBuild += "-language:experimental.macros"
libraryDependencies in ThisBuild ++= Seq(
"org.scala-lang" % "scala-reflect" % "2.10.0"
)
@Mononofu
Mononofu / merge.py
Created February 25, 2013 14:04
Merge two sorted arrays with no extra space. However, this runs in O(n^2) time.
#!/usr/bin/python
import random
try:
from termcolor import colored
except ImportError:
def colored(s, color):
return s
ERROR = 0
cmake_minimum_required(VERSION 2.6)
project(task1)
set(CMAKE_CXX_FLAGS "-g -Wall")
add_executable(sdc_client sdc_client.cpp)
target_link_libraries(sdc_client boost_program_options)
@Mononofu
Mononofu / client.cpp
Created April 15, 2013 08:00
Networked multi-user chat with auto-reconnect.
#include "zmq.hpp"
#include <string>
#include <iostream>
#include <pthread.h>
using namespace std;
void *msg_routine(void *arg) {
zmq::socket_t *message_source = (zmq::socket_t *) arg;
string ChatManager::newChat(){
Chat c;
c.name = "Chat"+(i++);
chats[c.name] = c;
return c.name;
}