Skip to content

Instantly share code, notes, and snippets.

View jsvensson's full-sized avatar

Johan Svensson jsvensson

View GitHub Profile
@jsvensson
jsvensson / Josephus.groovy
Last active August 29, 2015 14:21
Josephus solution in Groovy
class Josephus {
void execute(size = 41, steps = 3, survivors = 2) {
def prisoners = (1..size).toArray()
while(prisoners.length > survivors) {
(steps-1).times {
prisoners = prisoners.tail() + prisoners.head()
}
// Execute first prisoner
prisoners = prisoners.tail()

Keybase proof

I hereby claim:

  • I am jsvensson on github.
  • I am echo (https://keybase.io/echo) on keybase.
  • I have a public key whose fingerprint is 3DDF 3657 8F24 C60A 92FB 5612 6428 AFA9 4D92 7CF3

To claim this, I am signing this object:

@jsvensson
jsvensson / README.md
Last active December 30, 2015 22:19
MST3k-style names for humans in Starbound

Brick Manmeat? Slam McRockchest? You know you want these names!

Installation

  1. Create the folder mods/echo_mst3k/species in the root of your Starbound folder. This is found in Steam/steamapps/common/starbound.
  2. Download humannames.config below. Put it in mods/echo_mst3k/species.
  3. Inside the folder named after the platform you're running Starbound on (win32 for Windows), edit bootstrap.config. Add mods/echo_mst3k to the asset list. It should look like this:
{
@jsvensson
jsvensson / josephus.rb
Last active December 17, 2015 07:39
Josephus problem solution in Ruby.
def josephus(size, steps, survivors = 2)
list = *1..size
def list.[](i)
fetch(i % length)
end
puts "Population #{list.length}, #{steps} steps, #{survivors} survivors"
while list.length > survivors
@jsvensson
jsvensson / php-highlight.md
Created December 3, 2012 22:48
Octopress code PHP highlight test

Triple backticks

With opening tag, no closing tag

<?php 
  public function __construct(){
    parent::__construct();
  }
#encoding: utf-8
words = [
"Skapande",
"Möte",
"Musik",
"Kontor 1",
"Kontor 2",
"Må bra",
"Städ",
@jsvensson
jsvensson / gist:3893358
Created October 15, 2012 16:15 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
module SplitDeclarations
def self.split(dec)
dec = dec.split(/; ?/)
list = {}
dec.each do |d|
pair = d.split(/: ?/)
list[pair[0]] = pair[1]
end
list
end
var urlPrompt = $("<div>");
urlPrompt.attr({
class: 'UrlPrompt'
});
$(".ButtonBar").append(urlPrompt);
quickDrop = {
doBrowserWarning: function() {
var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
// Show warning box if unsupported browser
// Only work for Chrome atm since that what I develop in
// Will test Firefox when the basic functionality is in.
if (!isChrome)