Skip to content

Instantly share code, notes, and snippets.

View Mononofu's full-sized avatar

Julian Schrittwieser Mononofu

View GitHub Profile
@Mononofu
Mononofu / minimal.c
Created March 9, 2012 20:34
Minimal xscreensaver
/* xscreensaver, Copyright (c) 1992-2008 Jamie Zawinski <[email protected]>
*
* 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 / share.css
Created March 15, 2012 18:59
socialshareprivacy inline, without jQuery
.social_share_privacy_area {
clear: both;
margin: 20px 0 !important;
list-style-type: none;
padding: 0 !important;
width: auto;
height: 25px;
display: block;
}
.social_share_privacy_area li {
@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 / unscramble.scala
Created June 3, 2012 22:05
Text unscrambler
object Scramble extends App {
val words = io.Source.fromFile("/usr/share/dict/words").getLines()
val uniques = words.filter(! _.contains("'")).toList
// group words by what you get when you sort their individual characters
val scrambled_lookup = uniques.map(w => w.toList.sorted.mkString).zip(uniques).groupBy(_._1).map {
case (scrambled, ws) => (scrambled, ws.map(_._2))
}
// words whose sorted versions collide
val non_uniques = scrambled_lookup.toList.map(_._2).sortWith(_.length > _.length).filter(_.length > 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 / json.scala
Created September 18, 2012 11:34
Beautiful JSON handling in Scala
package EasyJSON
import net.minidev.json.JSONValue
import net.minidev.json.JSONArray
import net.minidev.json.JSONObject
import scala.collection.JavaConversions._
object JSON {
def parseJSON(s: String) = new ScalaJSON(JSONValue.parse(s))
@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)