Skip to content

Instantly share code, notes, and snippets.

@dmjio
dmjio / copy.c
Created August 22, 2012 18:52
Copy in 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 August 23, 2012 00:51
Making an elevator in C#
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 September 7, 2012 02:30
Parse url w/ js regex
//helper function
$.parseUrl = function(str) {
var match = str.match(/\/([^/]+)\/$/);
var a = match[1];
return a;
};
@dmjio
dmjio / ie.js
Created September 7, 2012 19:51
ie placeholder hack
(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 September 18, 2012 14:34
productexists
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");
@dmjio
dmjio / save_and_add_another.py
Created September 20, 2012 22:56
Save and add another
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 September 26, 2012 14:43
Stock Ticker App
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace StockTickerApp
{
class Program
{
@dmjio
dmjio / gist:3824464
Created October 3, 2012 01:49
poo.c
#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;
@dmjio
dmjio / gist:3831557
Created October 4, 2012 04:56
toLower.c
/*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 October 9, 2012 21:22
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:
list.append((j,l,))
return list