Skip to content

Instantly share code, notes, and snippets.

@xypaul
xypaul / merge2.js
Last active August 29, 2015 14:22
Improved Merge Sort JavaScript - http://jsbin.com/wiyaja
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 / main.m
Created June 5, 2015 05:29
Recreating the dataset from the MFS Paper by Bayne
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 / kmyself.m
Created June 5, 2015 05:30
My own implementation of kMeans Machine Learning algorithm in Matlab
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 / gist:4701837c4360c1012781
Created June 24, 2015 00:58
Power of 2 - recursive and bitwise :)
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 / gist:2afc58842d1890716af5
Created October 28, 2015 00:14 — forked from tausen/gist:4261887
pthread, sem_wait, sem_post example
#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 / ember-view.js
Created May 12, 2014 20:56
Ember - didInsertElement - afterRenderEvent - Ultimate solution
Ember.View.reopen({
didInsertElement : function(){
this._super();
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
},
afterRenderEvent : function(){
// implement this hook in your own subclasses and run your jQuery logic there
}
});
@xypaul
xypaul / gist:7037222
Last active December 25, 2015 20:39
Advanced CSS selections

Select the first five elements:

&:nth-child(-n+5}){

}
@xypaul
xypaul / base64.js
Created January 10, 2014 04:50 — forked from Marak/base64.js
/*
* base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
*
* (C) 2010, Nodejitsu Inc.
*
*/
var base64 = exports;
base64.encode = function (unencoded) {
@xypaul
xypaul / code.json
Last active January 6, 2016 01:59
language-code.json
{
"af": "Afrikaans",
"af-ZA": "Afrikaans (Suid-Afrika)",
"am": "አማርኛ",
"am-ET": "አማርኛ (ኢትዮጵያ)",
"ar": "العربية",
"ar-AE": "العربية (الإمارات العربية المتحدة)",
"ar-BH": "العربية (البحرين)",
"ar-DZ": "العربية (الجزائر)",
"ar-EG": "العربية (مصر)",
@xypaul
xypaul / tinymce-ember.js
Created May 14, 2014 06:32
TinyMCE 4 Ember Component
App.TinymceEditorComponent = Ember.Component.extend({
// Warning!!! only use tinyMCE not tinymce !!!
editor: null,
data: {},
watchData: true,
didInsertElement: function(){
var _this = this;
// The magic config - http://www.tinymce.com/wiki.php/Configuration
var config = {};