Skip to content

Instantly share code, notes, and snippets.

View PiJoules's full-sized avatar

PiJoules

  • Gotta increase that Github score
  • Not in Kansas
View GitHub Profile
@PiJoules
PiJoules / cosine.m
Last active August 29, 2015 14:24
Cosine Fourier Transformation
clear all; close all; clc;
W = 4;
Fs = 100; % large frequency to replicate continuous data (dt)
t = 0:1/Fs:W-1/Fs;
N = length(t);
x = cos(2*pi*t);
% Fourier transform
f = -10:1/Fs:10;
print list(set(map(int, raw_input().split()))) # takes a string of ints and returns the list with duplicates removed
@PiJoules
PiJoules / (un)install mysql
Created February 24, 2015 20:41
(Uninstalling + ) Installing MySQL for Mac
# Taken from https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks
# Remove MySQL
$ ps -ax | grep mysql # stop and kill any MySQL processes
$ brew remove mysql
$ sudo rm /usr/local/mysql
$ sudo rm -rf /usr/local/var/mysql
$ sudo rm -rf /usr/local/mysql*
# Install MySQL
@PiJoules
PiJoules / database transfer
Last active August 29, 2015 14:16
Command for transferring contents of one database to another one
# [oldpassword] is the password used for the old database and [newpassword] is the one for the destination database
# there is also no space between the -p and [old/newpassword]
$ mysqldump -h oldhost -u oldusername -p[oldpassword] olddbname | mysql -h newhost -u newusername -p[newpassword] newdbname
# This command can also be spilt into 2 ones if you want to perform them one at a time by saving the data into a temporary file
$ mysqldump -h oldhost -u oldusername -p[oldpassword] olddbname > temp.sql
$ cat temp.sql | mysql -h newhost -u newusername -p[newpassword] newdbname
# Delete the temp.sql with `rm temp.sql`
# If done the second way, you can also choose not to include the password when typing the command and instead type it later
@PiJoules
PiJoules / check-for-bootstrap
Last active August 29, 2015 14:13
Check if Bootstrap 2 or 3 is loaded
// Returns true if bootstrap is loaded, false otherwise
// Checks for Bootstra 2 or 3
// Based off this post: http://stackoverflow.com/questions/13933000/how-to-check-if-twitter-bootstrap-is-loaded
function bootstrapIsEnabled(){
return (typeof $().modal == 'function');
};
@PiJoules
PiJoules / Asynchronous Function Caller with Callback
Created January 13, 2015 20:46
Function for calling asynchronous functions
/**
* Pass a function to fn along with an optional callback
*/
function async(fn, callback) {
setTimeout(function() {
fn();
if (typeof callback !== "undefined")
callback();
}, 0);
@PiJoules
PiJoules / DynamicSort
Last active August 29, 2015 14:13
Function for sorting an array of objects by their properties
/**
* Function for sorting an array of objects by their properties.
* Based off this stackoverflow post: http://stackoverflow.com/questions/1129216/sorting-objects-in-an-array-by-a-field-value-in-javascript/4760279#4760279
*
* Example:
* var People = [
* {Name: "Name", Surname: "Surname"},
* {Name:"AAA", Surname:"ZZZ"},
* {Name: "Name", Surname: "AAA"}
* ];