Skip to content

Instantly share code, notes, and snippets.

View jonasbjork's full-sized avatar
🇸🇪
Everyday I am shuffelin'

Jonas Björk jonasbjork

🇸🇪
Everyday I am shuffelin'
View GitHub Profile
public class Main {
public static void main(String[] args) {
try {
java.net.InetAddress hostname = java.net.InetAddress.getLocalHost();
String hname = hostname.getHostName();
System.out.println("Hostname: " + hname);
} catch(Exception e) {
// Euler.java
public class Main {
public static void main(String[] args) {
int sum = 0;
for(int i=1; i<1000; i++) {
if( ((i%3)==0) || ((i%5)==0) ) {
sum += i;
System.out.println("i=" +i + " Sum=" + sum);
/**
* Euler2.java
*
* @author jonas
*/
public class Main {
/**
* @param args the command line arguments
*/
// Klocka.java
import java.awt.*;
import java.util.Date;
public class Klocka extends java.applet.Applet
implements Runnable {
Font teckensnittet=new
Font("Helvetica",Font.BOLD,18);
// Iteratedirs
import java.io.*;
import java.util.Iterator;
//import java.util.Vector;
import java.util.ArrayList;
/**
*
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>[404] Document Not Found</title>
<link rel="stylesheet" href="/blue-screen-of-death.css" type="text/css"></link>
<style>
html, body {
color: white;
background-color: #000080;
}
<?php
function mkpasswd($min, $max)
{
$pwd = "";
for($i=0; $i<rand($min,$max); $i++)
{
$num = rand(48,122);
if(($num >48 && $num < 57) || ($num >65 && $num < 90) || ($num > 97 && $num < 122))
{
@jonasbjork
jonasbjork / wp-resetpass.php
Created February 10, 2010 17:09
Resets admin pass on WP-site
<?php
/*
* Reset the admin password in a Wordpress site. Run this script from CLI!
*/
if($argc == 1) { die("[Error] You must specify the domainname!\nSyntax: ./$argv[0] <domainname>\n\n"); }
$_SERVER['HTTP_HOST'] = $argv[1];
printf("Trying to reset your administrative password, if successful you should get a [OK] back.\n\n");
define( 'WPPATH', dirname(__FILE__).'/' );
require( WPPATH.'wp-load.php' );
@jonasbjork
jonasbjork / illegalchars.php
Created March 3, 2011 10:23
Snippet for removing illegal chars from a string.
<?php
// Remove illegal chars, replacing them with a dash (-)
$str = "abc är du här? eLLller ELLER kanske däår?";
$str = preg_replace('/[^0-9a-zA-Z]+/', '-', $str);
// results in -> "abc-r-du-h-r-eLLller-ELLER-kanske-d-r-"
echo $str.PHP_EOL;
@jonasbjork
jonasbjork / spotify.el
Created August 17, 2011 20:38
Small minor mode to control spotify from emacs
;;Small minor mode to control spotify from emacs
(defun spotify-play () "Play Spotify" (interactive)
(shell-command "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play"))
(defun spotify-pause () "Pause Spotify" (interactive)
(shell-command "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause"))
(defun spotify-playpause () "Play/Pause Spotify" (interactive)
(shell-command "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"))