Skip to content

Instantly share code, notes, and snippets.

😇

Paul Knittel xypaul

😇
Block or report user

Report or block xypaul

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xypaul
xypaul / gist:2afc58842d1890716af5
Created Oct 28, 2015 — forked from tausen/gist:4261887
pthread, sem_wait, sem_post example
View gist:2afc58842d1890716af5
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <semaphore.h>
sem_t semaphore;
void threadfunc() {
@xypaul
xypaul / gist:4701837c4360c1012781
Created Jun 24, 2015
Power of 2 - recursive and bitwise :)
View gist:4701837c4360c1012781
public static Boolean powerCheck(int a) {
return a!=0 && (a & a-1) == 0;
}
public static Boolean recursivePowerCheck(int a){
if (a == 1) return true;
if (a == 0 || a % 2 != 0) return false;
return recursivePowerCheck(a/2);
}
@xypaul
xypaul / kmyself.m
Created Jun 5, 2015
My own implementation of kMeans Machine Learning algorithm in Matlab
View kmyself.m
function[r,l] = kmyself(dataSet, k)
% Determine the size of dataSet
[nRow, nCol] = size(dataSet);
% Empty array for cluster assesment
clusterAssment = zeros(nRow,2);
% Setup centroid and choose on to start of with
centroids = zeros(k,nCol);
@xypaul
xypaul / main.m
Created Jun 5, 2015
Recreating the dataset from the MFS Paper by Bayne
View main.m
function main()
% LOAD IRIS
% dataset was modified by changing the class name from string to a
% number
iris = load('iris.csv', ',');
% LOAD SONAR
sonar = load('sonar.csv', ',');
@xypaul
xypaul / merge2.js
Last active Aug 29, 2015
Improved Merge Sort JavaScript - http://jsbin.com/wiyaja
View merge2.js
function sort(array) {
var len = array.length;
if (len <= 1) {
return array;
}
var middle = Math.floor(len*0.5);
var left = array.slice(0,middle);
var right = array.slice(middle, len);
@xypaul
xypaul / merge.js
Last active Aug 29, 2015
Merge Sort JavaScript
View merge.js
function sort(array) {
var len = array.length;
var middle = Math.floor(len*0.5);
var left = array.slice(0,middle);
var right = array.slice(middle, len);
if (len == 1) {
return array;
} else {
@xypaul
xypaul / index.html
Created May 28, 2015
Improved Quick Sort Algorithm in JavaScript
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function quickSort(array, start, end) {
@xypaul
xypaul / main.java
Created May 28, 2015
101 - The Blocks Problem
View main.java
import java.io.*;
import java.util.*;
public class Main {
private static Stack[] Blocks;
private static PrintWriter out;
public static void main(String[] args) throws Exception {
@xypaul
xypaul / index.html
Created May 28, 2015
Quick sort implementation in JavaScript
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="ex"></div>
<script id="jsbin-javascript">
function qsort(ls){
@xypaul
xypaul / main.java
Created May 27, 2015
101 - The Blocks Problem
View main.java
import java.io.*;
import java.util.*;
public class Main {
private static Stack[] Blocks;
private static PrintWriter out;
public static void main(String[] args) throws Exception {
You can’t perform that action at this time.