Skip to content

Instantly share code, notes, and snippets.

View copy.c
#include <stdio.h>
/* copy input to output; 1st version */
int c;
c = getchar();
while (c != EOF) {
c = getchar();
dmjio / Elevator.cs
Created Aug 23, 2012
Making an elevator in C#
View Elevator.cs
using System;
using System.Threading;
namespace OOP
public class Program
private const string QUIT = "q";
public static void Main (string[] args)
dmjio / parseUrl.js
Created Sep 7, 2012
Parse url w/ js regex
View parseUrl.js
//helper function
$.parseUrl = function(str) {
var match = str.match(/\/([^/]+)\/$/);
var a = match[1];
return a;
dmjio / ie.js
Created Sep 7, 2012
ie placeholder hack
View ie.js
(function($) {
//This function will add placeholder text to IE
$.setPlaceHolderText = function() {
var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input');
if (PLACEHOLDER_SUPPORTED || !$(':input[placeholder]').length) {
$(':input[placeholder]').each(function() {
var el = $(this);
dmjio / prodExists
Created Sep 18, 2012
View prodExists
var productExists = function() {
var prod = $("#product_ok").css('display');
var brand = $("#brand_ok").css('display');
var btn = $("#btnSubmit");
if (prod != 'none' && brand != 'none') {
btn.attr('disabled', 'disabled');
btn.text("This product already exists");
def validate_add_another(add_another_msg, forgot_to_select_msg, last_product_msg, formset, request):
if 'add_another' in request.POST:
result = filter(lambda x : x.cleaned_data['select'], formset.forms)
#if this our last product to add and its been selected then just tell them it was saved, not to add another
if len(result) == len(formset.forms):
return last_product_msg
#if they hit the add another while selecting products (and its not the last product) tell them to add more
elif any(result):
return add_another_msg
#if they hit the save and add another button but forget to assign
dmjio / stockReader.cs
Created Sep 26, 2012
Stock Ticker App
View stockReader.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace StockTickerApp
class Program
View gist:3824464
#include <ctype.h>
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
int is_numeric(char str[])
int i, v, d, n;
double l, j;
View gist:3831557
/*lower:convert c to lowercase; ASCII only*/
int lower(int c)
if (c >= 'A' && c <= 'Z')
return c +'a'-'A';
return c;
dmjio /
Created Oct 9, 2012
Inversion finder
def invFinder(a): #O(n^2) :-/
list = []
for i,j in enumerate(a):
for k,l in enumerate(a):
if i < k and j > l:
return list