Skip to content

Instantly share code, notes, and snippets.

@dmdevoss
dmdevoss / gist:c9b30802e31c96c9ca25
Last active August 29, 2015 14:07
Simple function to count up new listings based on type.
/*
* Description:
* Returns a count of new listings, ratings, students, landlords, or roommate requests
* that were made within 30 days.
*
* Input:
* $type = 'listings', 'ratings', 'students', 'landlords', or 'roommate'.
*
*/
@dmdevoss
dmdevoss / gist:211622f8835a04b2dc75
Created October 7, 2014 15:15
Non-recursive free nodes in C
void free_list(node** head){
while(*head){
node* next = (*head)->next;
(*head)->next = NULL;
free(*head);
*head = next;
}
};
@dmdevoss
dmdevoss / gist:19659da45eb12ce462f3
Created July 29, 2014 18:52
Global errors for angular 1.3
var globalErrors = new angular
.module('globalErrors', [])
.config(function($provide, $httpProvider, $compileProvider) {
var elementsList = $();
var showMessage = function(content, cl, time) {
$('<div/>')
.addClass('globalAlertMessage')
.addClass(cl)
.fadeIn('fast')
@dmdevoss
dmdevoss / gist:ae4ed6e2fa94c9ccd62b
Created May 27, 2014 14:47
Searches an array of meta values, if it doesn't find it, it creates a new json object, pushes it on and returns its index.
$scope.arraySearch = function (array, key) {
for (var i = array.length - 1; i >= 0; i--) {
console.log(array[i].meta_key);
if (array[i].meta_key === key){
console.log("Found " + key + " at " + i);
return i;
}
};
console.log("Could not find " + key);
var newJson = {
@dmdevoss
dmdevoss / gist:11261926
Last active August 29, 2015 14:00
skeleton to a csv->mysql db migration in php
<?php
$connect = new PDO('mysql:host=localhost;dbname=db',"user","pass");
$file = fopen("myCSVFile.cvs", 'r');
do {
if ($data[0]) {
$connect->exec("INSERT INTO myTable (col1, col2, col3, col4, col5) VALUES
(
@dmdevoss
dmdevoss / gist:10209837
Created April 8, 2014 23:45
Check binary tree's values are where they should be in the tree.
/**
* Return true if keys in this subtree are never null and are correctly sorted
* and are all in the range between the lower and upper (both exclusive).
* If either bound is null, then that means that there is no limit at this side.
* @param node root of subtree to examine
* @param lower value that all nodes must be greater than. If null, then
* there is no lower bound.
* @param upper value that all nodes must be less than. If null,
* then there is no upper bound.
* @return true if the subtree is fine. If false is returned, a problem