Skip to content

Instantly share code, notes, and snippets.

@soundsmitten
soundsmitten / mColor.java
Created December 12, 2012 22:34
Java M-Coloring Graph algorithm.
// Wikipedia: a way of coloring the vertices of a graph such that no two
// adjacent vertices share the same color; this is called a vertex coloring.
// Similarly, an edge coloring assigns a color to each edge so that no two adjacent
// edges share the same color, and a face coloring of a planar graph assigns a color to
// each face or region so that no two faces that share a boundary have the same color.
// In NP-complete
boolean mcolor(int i, int m, int n, bool [][] W, int [] vcolor, int n)
{
// i: last colored vertex
// m: number of colors
@soundsmitten
soundsmitten / prim.java
Created December 12, 2012 22:39
Java- Prim's minimum spanning tree
// From Wikipedia: Prim's algorithm is a greedy algorithm that
// finds a minimum spanning tree for a connected weighted undirected graph.
// This means it finds a subset of the edges that forms a tree that
// includes every vertex, where the total weight of all the edges in the tree is minimized.
void Prim(int n, int[][] W, int[] nearest)
{
int[]distance
for( i = 1; i<=n; i++)
{
@soundsmitten
soundsmitten / Dijkstra.java
Created December 12, 2012 22:41
Java- Dijkstra's algorithm
// From Wikipedia: For a given source vertex (node) in the graph, Dijkstra's algorithm finds the
// path with lowest cost (i.e. the shortest path) between that vertex and every other vertex.
void Dijkstra(int n, int [][] W, int source, int[] touch, int[] distance, int[totalCost])
{
int [] length
for(int i = 1; i<=n; i++)
{
touch[i] = source
length[i] = W[source][i]
}
@soundsmitten
soundsmitten / nQueens.java
Created December 12, 2012 22:59
Java- n-queens problem
// The eight queens puzzle is the problem of placing eight chess queens on an 8?8
// chessboard so that no two queens attack each other. Thus, a solution requires that no two
// queens share the same row, column, or diagonal. The eight queens puzzle is an example of the more general
// n-queens problem of placing n queens on an n?n chessboard,
// where solutions exist for all natural numbers n with the exception of 2 and 3.[
boolean promising (int i, int[] col) {
for (j=1; j<i; j++) {
if (col[i] == col[j]) {
return false;
}
@soundsmitten
soundsmitten / floyd.java
Created December 12, 2012 23:07
Java- Floyd's algorithm
// Wikipedia: a graph analysis algorithm for finding shortest paths in a weighted graph
// (with positive or negative edge weights) and also for finding transitive closure of a
// relation R. A single execution of the algorithm will find the lengths (summed weights)
// of the shortest paths between all pairs of vertices, though it does not return details
// of the paths themselves. The algorithm is an example of dynamic programming.
public void floyd(int n, int[][] W, int[][] P, int[][] D)
{
D = W;
for (int i = 0; i<n; i++)
@soundsmitten
soundsmitten / rss.mm
Created December 12, 2012 23:34
Objective-C Getting titles and descriptions in RSS feed
-(void) retrieveFromInternet {
NSURLRequest * request = [NSURLRequest requestWithURL: [self feedUrl]];
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString * pageSource = [[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding];
// NSLog(@"%@", pageSource);
[self setNewsStories: [self getHeadersAndSnippetsFromSource: pageSource]];
}
- (NSArray *) getHeadersAndSnippetsFromSource: (NSString *) pageSource {
NSArray * feedItems = [pageSource componentsSeparatedByString:@"<item>"];
NSMutableArray * titlesAndSnippets = [[NSMutableArray alloc]init];
@soundsmitten
soundsmitten / seguepass.mm
Created December 13, 2012 00:12
Objective-C: Example of Passing info from ViewController back to PreviousViewController
// AddViewController- has fields where data is entered.
AddViewController.h
@protocol AddDelegate <NSObject>
-(void) saveMySeconds: (int) seconds andTitle: (NSString*)activity;
@end
//AddViewController.m
#pragma mark text field delegate method
-(BOOL)textFieldShouldReturn:(UITextField *)textField { // dismiss keyboard on return.
[textField resignFirstResponder];
return YES;
tell application "BBEdit" to set theFile to file of document 1
tell application "Finder" to set theFolder to (container of file theFile) as alias
set theUnixPath to POSIX path of theFolder
tell application "iTerm"
activate
set myTerm to (make new terminal)
tell myTerm
launch session "Default"
set _session to current session
end tell
@soundsmitten
soundsmitten / gist:ad44081981f54cd47b8c
Created May 28, 2014 18:00
Configuration.plist for Radicale Carddav
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_className</key>
<string>PHXCardDAVSource</string>
<key>disabled</key>
<false/>
<key>homeInfo</key>
### Keybase proof
I hereby claim:
* I am imightbewrong on github.
* I am njlash (https://keybase.io/njlash) on keybase.
* I have a public key whose fingerprint is 80C8 96A0 DBDB 120D ED97 C719 E99E 79CB E34C 6588
To claim this, I am signing this object: