Skip to content

Instantly share code, notes, and snippets.

View copy.c
#include <stdio.h>
/* copy input to output; 1st version */
main()
{
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
@dmjio
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
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
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) {
return;
}
$(':input[placeholder]').each(function() {
var el = $(this);
@dmjio
dmjio / prodExists
Created Sep 18, 2012
productexists
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");
View save_and_add_another.py
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
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';
else
return c;
}
@dmjio
dmjio / inv_finder.py
Created Oct 9, 2012
Inversion finder
View inv_finder.py
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:
list.append((j,l,))
return list