Skip to content

Instantly share code, notes, and snippets.

View lebbe's full-sized avatar

Lars-Erik Bruce lebbe

View GitHub Profile
@lebbe
lebbe / testStorageAbilities.html
Last active December 13, 2015 19:28
Something I threw together to test storage abilities in different browsers.
<!--
Something I threw together to test storage abilities in different browsers.
This test two forms of session storages: html 5 session storages, and the window.name fallback option.
It also tests two forms of persistent storage: html 5 local storage and cookies.
Intended usage:
Upload the html file to your web-server.
@lebbe
lebbe / gist:6007877
Last active December 19, 2015 19:39
Simple stuff to pretty print parameters of an url on terminal. I know this shouldn't be done in Java, but bear ... A BEAR :O
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class FormatUrlParameters {
public static String printFormat(String url) {
Map<String, String> mapper = new HashMap<String, String>();
worlds["world"] = "/home/minecraft/terranova/world"
renders["normalrender"] = {
"world": "world",
"title": "Normal Render of My World",
"rendermode": smooth_lighting,
"dimension": "overworld",
}
optimizeimg = 1
@lebbe
lebbe / HTMLUtil.java
Last active December 22, 2015 00:09
Compute the class attribute for a html tag
class HTMLUtil {
// ... other code
public static String styleClass(String ... styleClasses) {
StringBuffer result = new StringBuffer();
result.append("class=\"");
for(String styleClass: styleClasses)
if(styleClass != null)
@lebbe
lebbe / gist:6464236
Created September 6, 2013 14:01
Just some javascript which wraps a span-element around all text nodes within a given node. This is not useful in itself, but is a skeleton for future javascript which want to convert text on a page some way or another. Only tested in chrome for now.
<script type="text/javascript">
"use strict";
function changeAll() {
wrapSpan(
document.getElementsByTagName('body')[0], 0
);
}
/**
* Wrap a span element around all text nodes.
@lebbe
lebbe / HTMLUtil.java
Last active December 23, 2015 10:39
shyfy
public static String shyfy(String text, int maxWidth) {
int length = text.length();
if(length <= maxWidth)
return text;
StringBuilder result = new StringBuilder();
int wordLength = 0;
for(int i = 0; i < length; i++) {
char c = text.charAt(i);
@lebbe
lebbe / findfont.js
Created October 30, 2013 10:01
I was looking for a font on android supporting the &#9003; character. Did not find any. You can turn this code into a "font with &#9003;"-detector, by measuring the width of the span &#9003; is inside.
$(function() {
var fonts = ["cursive", "monospace", "serif", "sans-serif", "fantasy", "default", "Arial", "Arial Black", "Arial Narrow", "Arial Rounded MT Bold", "Arial Unicode", "Bookman Old Style", "Bradley Hand ITC", "Century", "Century Gothic", "Comic Sans MS", "Courier", "Courier New", "Droid Sans", "Droid Serif", "Droid Sans Mono", "Georgia", "Gentium", "Impact", "King", "Lucida Console", "Lalit", "Modena", "Monotype Corsiva", "Papyrus", "Tahoma", "TeX", "Times", "Times New Roman", "Trebuchet MS", "Verdana", "Verona"];
var $testField = $('<span>&#9003;</span>');
for(var i = 0; i < fonts.length; i++) {
$clone = $testField.clone();
$clone.css({
'font-family': fonts[i]
});
@lebbe
lebbe / mcbot.js
Last active December 27, 2015 14:39
minecraft irc bot
var spawn = require('child_process').spawn,
minecraftProcess = spawn('java', ['-jar', 'minecraft_server.1.7.2.jar'], {
cwd: 'Absolute path to minecraft server jar here!'
});
var util = require("util");
var irc = require('irc'); // Remember to run "npm install irc!"
var channel = "channel name here, remember '#' before the name!";
var bot = new irc.Client("irc server here", "bot name here", {
@lebbe
lebbe / validUTF8variablenamecharacters.js
Created January 14, 2014 15:59
Find the UTF8 code points which can be used in variable names in javascript. (PS, this will take some time to complete. Let me know when you are done.)
var hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
var upper = 15;
for(var a = 0;a<=upper;a++) {
for(var b = 0;b<=upper;b++) {
for(var c = 0;c<=upper;c++) {
for(var d = 0;d<=upper;d++) {
@lebbe
lebbe / checkGarbage.js
Last active January 3, 2016 23:59
Check out how many custom defined functions there are defined directly in global scope.
// This checks specifically for accidental garbage by trying to delete
// fields in window. If it is deleteable, and it is undefined after delete
// it means one of two things:
// 1. It is a field in which you forgot to declare "var" in front
// 2. It is a field you have placed on global scope on purpose ("window.something =")
!function() {
var count = 0;
for(var f in window) {
if(typeof window[f] !== "function" && delete window[f] && typeof window[f] === "undefined") {