This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//assume we're looking for x. | |
bool found = false; | |
Node* temp = head, rm = NULL; | |
//now we loop through our list looking for a node that holds something == to x | |
while(temp != null && !found) { | |
if(temp->data == x) { //if we find it, set found to true and rm to the node | |
found = true; | |
rm = temp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//let's say we're replacing this: | |
public MyChatListener extends ChatListener { | |
public void onPlayerChat(PlayerChatEvent event) { | |
//do something | |
} | |
} | |
//We'll change it to this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var remainingTime := 5 | |
procedure run() | |
if(remainingTime <= 0) then | |
Bukkit.shutdown() | |
else | |
print("Halt in " + remainingTime) | |
remainingTime-- | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildMaxHeap(data) | |
//Precondition: data is an ordered set that contains n elements | |
data.heapSize = data.length | |
//Loop invariant: the trees rooted at indices in the range [i,n] are max-heaps | |
for i=FLOOR(data.length/2) downto 1 | |
maxHeapify(data, I) | |
//Postcondition: data[1] is the root of a tree that is a max-heap | |
mergeSort(data) | |
//Precondition: data is an ordered set of n elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Precondition: A is a list of elements, sorted in increasing order | |
// P is the root of the binary tree to be created | |
//Postcondition: P is the root of a binary tree containing all elements in A | |
procedure mktree(list A, node P) | |
if A is empty, | |
return | |
middle = A.length/2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Server has client's public key already, in a list of trusted public keys | |
keys are RSA key pairs | |
client connects | |
server sends its pubkey | |
client now using server's pubkey to encrypt all outgoing communications, incoming are still unencrypted | |
client sends username it wants to authenticate as | |
server loads trusted pubkey for username | |
encrypts n securely-randomly-generated bytes, sends over unencrypted connection to client | |
client uses private key to decrypt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void deleteTown(ObjectOutputStream oos, ObjectInputStream ois) throws IOException, ClassNotFoundException { | |
//receive arguments over socket | |
final String townName = (String) ois.readObject(); | |
final FutureBoolean result = new FutureBoolean(); | |
final Object callback = this; | |
//prepare a Runnable object to delete the town from the server's main thread | |
Runnable r = new Runnable() { | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client connects to server | |
<authentication happens> | |
client writes a RemoteAction enum to signal what it wants to do (ADD_PLAYER, REMOVE_PLAYER, etc) | |
server reads enum, uses a big switch-case to direct flow to appropriate method | |
in the appropriate method, server reads in "arguments" for action one by one, as client sends them | |
server executes the action once it has all its input | |
server communicates back exit status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.Graphics; | |
import javax.swing.JFrame; | |
import javax.swing.SwingWorker; | |
public class MuhJFrame extends JFrame { | |
private SwingWorker gameLooper; | |
private boolean stop; | |
private int seconds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2013 everdras@gmail.com | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
OlderNewer