Facebook Website Integration – HTML


To integrate Facebook on to a website without the use of a facebook app you need these things:

Once you have both of those things you can do this in feedburner:

  • Add a new feed (your facebook url)
  • Go to the publicize tab
  • Go to BuzzBoost
  • Sroll down and fill out the form, you will be given html code.
  • <script src="http://feeds.feedburner.com/DanielFolkessFacebookStatusUpdates?format=sigpro" type="text/javascript" ></script>
    <noscript><p>Subscribe to RSS headline updates from: 
    <a href="http://feeds.feedburner.com/DanielFolkessFacebookStatusUpdates"></a>
    <br/>Powered by FeedBurner</p> 
    </noscript>
  • Preview:

And that’s it!
You can now style it up a little bit with some CSS and stuff.

Java – Singleton / Global – Data Access – SQLite

This will make a Java global object:

import java.io.File;
import java.io.IOException;
 
import com.almworks.sqlite4java.SQLite;
import com.almworks.sqlite4java.SQLiteConnection;
import com.almworks.sqlite4java.SQLiteException;
import com.almworks.sqlite4java.SQLiteJob;
import com.almworks.sqlite4java.SQLiteQueue;
import com.almworks.sqlite4java.SQLiteStatement;
 
public final class DataAccess {
	// Singleton Stuff
	private static class SingletonHolder { 
	     public static final DataAccess INSTANCE = new DataAccess();
	}
	public static DataAccess getInstance() {
	     return SingletonHolder.INSTANCE;
	}
	// End Singleton Stuff
 
 
	private String HomePath = "";
	private File DBFile;
	private static SQLiteQueue queue;
	private boolean initalized = false;
 
	private DataAccess()
	{
		if (!initalized)
		{
			initDB();
 
			initalized = true;
		}
	}
 
	private void initDB()
	{
		DBFile = locateDBFile();
		DeleteDatabaseContents();
	}
	private File locateDBFile()
	{
		File f = null;
		try{
			HomePath = System.getProperty("user.home");
    	    System.out.println("HomePath: " + HomePath);
    	    f = new File(HomePath + "/database.sqlite");
    	    if (f.canRead())
    	    	return f;
    	    else
    	    {
        	    boolean success = f.createNewFile();
        	    if (success) {
        	        // File did not exist and was created
        	    } else {
        	        // File already exists
 
        	    }
    	    }
    	} catch (IOException e) {
    		//Maybe try a new directory.
    	}
		return f;
	}
 
	private void DeleteDatabaseContents()
	{
		queue.execute(new SQLiteJob<Object>() 
		{
		    protected Object job(SQLiteConnection connection) throws SQLiteException 
		    {
		      // this method is called from database thread and passed the connection
				StringBuilder sb = new StringBuilder();
				sb.append("DROP TABLE IF EXISTS Playlist;");
				sb.append("DROP TABLE IF EXISTS Settings;");
				//sb.append("DELETE FROM someTable;");
				//sb.append("DELETE FROM someTable;");
 
 
				connection.exec(sb.toString());
				return null;
		    }
		});
	}
	public String getHomePath()
	{
		return HomePath;
	}
}

Now you can run this from anywhere:

DataAccess da;
da = DataAccess.getInstance();

Source: http://en.wikipedia.org/wiki/Singleton_pattern

PHP API – Google Calendar – Updating Visibility

The Privacy / Visibility Part:

$event->visibility->value = "http://schemas.google.com/g/2005#event.private";

Here it is in context: Continue reading “PHP API – Google Calendar – Updating Visibility”

Minecraft – Script – Backup – Update Server – Restart

This is the script I use that will:

  • Automatically backup minecraft map
  • Automatically update minecraft server
  • Automatically restart the server if it stops or dies
#!/bin/bash
while [ true ]; do
   # make md5 of current file for update check.
   md5sum minecraft_server.jar > minecraft_server.jar.md5
   wget -o updatelog.log -N --trust-server-names http://www.minecraft.net/download/minecraft_server.jar
   # display updated status
   if md5sum -c --status minecraft_server.jar.md5 
   then
    echo "Server Up to Date."
   else
    echo "Updated Server!"
   fi
   java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
   rsync -a --delete --progress /home/dan/serv/minecraft/world "/home/dan/serv/minecraft/bak/world"`eval date +%Y%m%d`""
done

Code Explained:

This will put the server in an infinite loop. You can kill it by hitting Control+C a couple times in a row.

while [ true ]; do

This will make a hash of the current minecraft_server.jar and then download the newest copy using wget.

md5sum minecraft_server.jar > minecraft_server.jar.md5
wget -o updatelog.log -N --trust-server-names http://www.minecraft.net/download/minecraft_server.jar

This will run minecraft in headless mode and with a limit on RAM.

java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui

This will create a backup of the minecraft world folder in a backup folder. You probably should work on this part.

rsync -a --delete --progress /path/to/minecraft/world "/path/to/minecraft/bak/world"`eval date

Well, hope this helps someone. Have a good day.

Rsync – Speed Limit – Trickle – Slow

Install rsync and trickle:

sudo apt-get install rsync
sudo apt-get install trickle

Now you can run rsync:
This will download at a limit of 80 KB/s from host:

rsync -auvPe "trickle -d 80 ssh" user@host:/src/ /dst/

Explanation of Commands:

-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
-u, --update                skip files that are newer on the receiver
-v, --verbose               increase verbosity
-P  --progress              show progress during transfer
-e, --rsh=COMMAND           specify the remote shell to use
trickle -d 80  = -d rate    Limit the download bandwidth consumption to rate KB/s.

Outlook Rule : Only at Specific Times

Lets say you want to have a rule in outlook send to you only between specific times in the day.

  • Only after 6pm and before 8am
  • Only on your lunch hour
  • When you are not at work

I will explain this by having emails forward to my cell phone, only when I am normally not at the office. (From 6pm-8am) This way, I will be able to receive important emails that may require special outside assistance.

What I do is:

  • Create a special category called FWD
  • Use other rules to set messages into the FWD category if I want them forwarded. (Explained Below)
  • Then, create a rule to run last in the rules list called FWD Rule
  • *Important Part* This will check the time on the messages, if it’s within the specified hours, it will forward the email (Explained Below)

Creating a Rule to set the FWD Category:
Your Rule Description should look something like this. The important part is that it is assigning it to the FWD Category:

Apply this rule after the message arrives
with 'Emergency from client' in the subject
    and marked as 'high importance'
    and assigned to 'FWD' Category

The Rule that will email header* for UTC times. Make sure it’s assigned to the FWD category. And then FWD it:

Apply this rule after the message arrives
with '2011 23:' or '2011 02:' or ... '2011 10:' in the message header
    and assigned to 'FWD' category
forward it to '[email protected]'

* This should work on most emails, but if you want to look at the email header Right-click on the message in the Inbox and select Message Options.
* I included the 2011 and the colon to make it more specific.

UTC Time for 6pm – 8am:
Email Header contained:
X-OriginalArrivalTime: 18 Feb 2011 03:23:52.0368 (UTC)
So I searched for:

2011 23:,2011 01:,2011 02:,2011 03:,2011 04:,2011 05:,2011 06:,2011 07:,2011 08:,2011 09:,2011 10:,2011 11:

jQuery – Ajax – Extra Parameters – GET, success

Here is the standard jQuery Ajax call with success handler as well as the ability to pass another parameter to an external function:

	$.ajax({
			type: "GET",
			url: Humancurl,
			dataType: "xml",
			success: function(data){
				NameOfFunctionToParseReturnedData(data,ExtraParameter);
			}
		});

Here is the standard jquery ajax call with success handler:

$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.'+data);
  }
});

Ubuntu Samba – Read-Write-FSTAB-Cifs-Mount


This is my current setup for my two Ubuntu 10.10 (Maverick Meerkat) boxes. One shares a read/write folder to the other. This is my setup. I think the key to this is having the same username on both computers having access to the files.

You might have to run this on the the folder:
sudo chmod -R 777 /path/to/files
sudo chown -R usernameonbothcomputers:usernameonbothcomputers /path/to/files

I installed samba by doing: sudo apt-get install samba

/etc/samba/smb.conf : (on the computer serving the files)

[global]
	workgroup = WORKGROUP
	server string = %h server (Samba, Ubuntu)
	dns proxy = no
 
	interfaces = 127.0.0.0/8 eth0
	bind interfaces only = yes
 
	log file = /var/log/samba/log.%m
	max log size = 1000
	syslog = 0
 
	panic action = /usr/share/samba/panic-action %d
	encrypt passwords = true
	passdb backend = tdbsam
	obey pam restrictions = yes
	unix password sync = yes
	passwd program = /usr/bin/passwd %u
	passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
	pam password change = yes
 
	guest account = nobody
	invalid users = root
	usershare allow guests = yes
 
[MyFiles]
	path = /path/to/share
	writable = yes
	read only = no
	valid users = usernameonbothcomputers

sudo /etc/init.d/smbd reload

/etc/fstab : (on the computer accessing the files)

//SAMBASHAREsSERVERNAME/MyFiles /path/to/mount cifs users,,noatime,username=usernameonbothcomputers,password=theuserspassword 0 0

You should be able to run this to mount all things in your fstab:
sudo mount -a

.Net – Sending Email with In Memory Attachment

This VB.Net code takes the FileUpload control’s PostedFile and without saving it to the filesystem attaches it to an MailMessage and sends an email.

Advantages:

  • No threading, read/write permissions needed.
  • One line of code.

Front End:

<asp:FileUpload ID="fileUpload" runat="server" />

Code:

Dim m As New MailMessage()
m.Attachments.Add(New Attachment(fileUpload.PostedFile.InputStream, fileUpload.FileName))