Skip to content

Instantly share code, notes, and snippets.

@clsnyder
clsnyder / R-Split DFbyChar.r
Last active August 29, 2015 14:12
R Statistics - How to split a dataframe column by a character
# How to import operations for analysis
# Step 1: Import the dataset as 'ops'
# The '$PREOP.DIAGNOSIS.1' columnn (and postop col) looks like this -> "752.51 - UNDESCENDED TESTIS"
# So we want to make two columns from either side of the '-'
ops$dxDescr <- lapply(strsplit(as.character(ops$PREOP.DIAGNOSIS.1), "\\-"), "[", 2)
ops$dxCode <- lapply(strsplit(as.character(ops$PREOP.DIAGNOSIS.1), "\\-"), "[", 1)
ops$opDescr <- lapply(strsplit(as.character(ops$PROCEDURE.1), "\\-"), "[", 2)
ops$opCode <- lapply(strsplit(as.character(ops$PROCEDURE.1), "\\-"), "[", 1)
@clsnyder
clsnyder / evernoteBU.scpt
Created January 4, 2015 21:34
Evernote Backup
-- PURPOSE: Export all notes in Evernote to an ENEX file so that
-- the notes can be backed up to an external drive or to the cloud
-- Change the path below to the location you want the notes to be exported
set f to "/Volumes/hd1T/Backup/Dropbox/evernoteBU/Export.enex"
with timeout of (30 * 60) seconds
tell application "Evernote"
-- Set date to 1990 so it finds all notes
set matches to find notes "created:19900101"
@clsnyder
clsnyder / replaceText.js
Created January 2, 2015 22:42
Javascript snippet to change text with markers
<body>
<p>Click the button to Fill in </p>
<textarea rows="10" cols="60" id="demo"></textarea>
<br/>
<script>
function myFunction2()
{
@clsnyder
clsnyder / app.js
Last active August 29, 2015 14:12 — forked from jrmoran/app.js
How to Load and external json file in Angularjs
var App = angular.module('App', []);
App.controller('TodoCtrl', function($scope, $http) {
$http.get('todos.json')
.then(function(res){
$scope.todos = res.data;
});
});
@clsnyder
clsnyder / Search box
Last active August 29, 2015 14:12
HTML and CSS for Nice Search Box
@clsnyder
clsnyder / getJsonFromMySQL.php
Created December 24, 2014 18:45
This gets the data from a mySQL server via PDO and converts to JSON for the angular app
<?php
// set up the connection variables
$db_name = 'test';
$hostname = 'localhost';
$username = 'root';
$password = 'root';
// connect to the database
$dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
@clsnyder
clsnyder / gist:a685691ae9cd992ffea6
Last active August 29, 2015 14:11
Create an HTML table from JSON
// Source - http://stackoverflow.com/questions/14062368/new-recommended-jquery-templates/14062431#14062431
//HTML
<script type="text/template" id="cardTemplate">
<div>
<a href="{0}">{1}</a>
</div>
</script>
<div id="container">
</div>
@clsnyder
clsnyder / ShuffleJson
Created November 17, 2014 00:23
Fisher-Yates-Durstenfeld shuffle for JSON
shuffle(yourQuestionArray);
shuffle(yourTopicArray);
// ...
function shuffle(sourceArray) {
for (var n = 0; n < sourceArray.length - 1; n++) {
var k = n + Math.floor(Math.random() * (sourceArray.length - n));
var temp = sourceArray[k];
@clsnyder
clsnyder / CreateJSONFromSample
Last active August 29, 2015 14:09
Retrieve JSON from mySQL Query - 1
CREATE TABLE IF NOT EXISTS `employee` (
`id_employee` int(3) unsigned NOT NULL AUTO_INCREMENT,
`emp_name` varchar(10) DEFAULT NULL,
`designation` varchar(9) DEFAULT NULL,
`date_joined` date DEFAULT NULL,
`salary` decimal(7,2) DEFAULT NULL,
`id_dept` int(2) DEFAULT NULL,
PRIMARY KEY (`id_employee`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
@clsnyder
clsnyder / Create a table from php query automatically
Created November 8, 2014 14:44
Automatically creates an HTML table from a PHP query if you supply the desired mySQL column names
<?php
$host = "localhost";
$user = "root";
$pass = "root";
$db = "test";
$link = mysql_pconnect($host, $user, $pass) or die("Could not connect");
mysql_select_db($db) or die("Could not select database");