date_select conversion
<%=date_select(:date,'',:start_year => 1950,:include_blank => false, :default => { :year => '1970' })%> def convert_date(obj) return “#{obj[‘(1i)’]}-#{obj[‘(2i)’]}-#{obj[‘(3i)’]}” end
11332 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
<%=date_select(:date,'',:start_year => 1950,:include_blank => false, :default => { :year => '1970' })%> def convert_date(obj) return “#{obj[‘(1i)’]}-#{obj[‘(2i)’]}-#{obj[‘(3i)’]}” end
function selectHelper($values, $match) { $keys = array_keys($values); $i = 0; foreach($values as $option) { $selected = null; if($match == $keys[$i]) $selected = " selected"; echo " <option value=\"".$keys[$i]."\"$selected>".$option."</option>\n"; $i++; } } //sample usage: $values = array( "lb" => "Pounds", "ea" => "Each", "oz" => "Ounces"); selectHelper($values, $product->unit);
SELECT TABLE_CATALOG , TABLE_SCHEMA , TABLE_NAME , ORDINAL_POSITION , COLUMN_DEFAULT , IS_NULLABLE , DATA_TYPE , CHARACTER_MAXIMUM_LENGTH , COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = (N'Persons')
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ‘TEST’ AND COLUMN_NAME = ‘TEST_DATE’) BEGIN ALTER TABLE TEST ADD TEST_DATE DATETIME END
<%= date_select('range', 'start_date', :order => [:month, :day, :year])%>
@start_date = Date.civil(params[:range][:"start_date(1i)"].to_i,params[:range][:"start_date(2i)"].to_i,params[:range][:"start_date(3i)"].to_i)
#include <stdio.h> typedef struct { int len; int e[102]; } List; void printv(char *msg, List l) { printf("%s", msg); int i; for (i = 0; i < l.len; ++i) printf("%d ", l.e[i]); printf("\n"); } int pivot(List *l, int p, int r) { int x = l->e[r]; int i = p - 1; int j = r + 1; while (1) { do { ++i; } while (l->e[i] < x); do { --j; } while (l->e[j] > x); //printf("%d %d\n", i, j); if (i < j) { int aux = l->e[i]; l->e[i] = l->e[j]; l->e[j] = aux; } else return i - 1; } } int selectv(List *l, int nrp, int p, int r) { //printf("p, r: %d, %d\n", p, r); //printf("nrp: %d\n", nrp); //printv("l: ", *l); if (p == r) return l->e[p]; if (p < r) { int q = pivot(l, p, r); //getchar(); if (q - p + 1< nrp) return selectv(l, nrp - (q - p) - 1, q + 1, r); return selectv(l, nrp, p, q); } return -1; } int main(int argc, char *argv[]) { List l; l.len = 100; int i; for (i = 0; i < l.len; ++i) l.e[i] = l.len - i; int nth = 56; printf("%d: %d\n", nth, selectv(&l, nth, 0, l.len - 1)); //printv("L: ", l); return 0; }
//+ Jonas Raoni Soares Silva //@ http://jsfromhell.com/forms/selection [v1.0] Selection = function(input){ this.isTA = (this.input = input).nodeName.toLowerCase() == "textarea"; }; with({o: Selection.prototype}){ o.setCaret = function(start, end){ var o = this.input; if(Selection.isStandard) o.setSelectionRange(start, end); else if(Selection.isSupported){ var t = this.input.createTextRange(); end -= start + o.value.slice(start + 1, end).split("\n").length - 1; start -= o.value.slice(0, start).split("\n").length - 1; t.move("character", start), t.moveEnd("character", end), t.select(); } }; o.getCaret = function(){ var o = this.input, d = document; if(Selection.isStandard) return {start: o.selectionStart, end: o.selectionEnd}; else if(Selection.isSupported){ var s = (this.input.focus(), d.selection.createRange()), r, start, end, value; if(s.parentElement() != o) return {start: 0, end: 0}; if(this.isTA ? (r = s.duplicate()).moveToElementText(o) : r = o.createTextRange(), !this.isTA) return r.setEndPoint("EndToStart", s), {start: r.text.length, end: r.text.length + s.text.length}; for(var $ = "[###]"; (value = o.value).indexOf($) + 1; $ += $); r.setEndPoint("StartToEnd", s), r.text = $ + r.text, end = o.value.indexOf($); s.text = $, start = o.value.indexOf($); if(d.execCommand && d.queryCommandSupported("Undo")) for(r = 3; --r; d.execCommand("Undo")); return o.value = value, this.setCaret(start, end), {start: start, end: end}; } return {start: 0, end: 0}; }; o.getText = function(){ var o = this.getCaret(); return this.input.value.slice(o.start, o.end); }; o.setText = function(text){ var o = this.getCaret(), i = this.input, s = i.value; i.value = s.slice(0, o.start) + text + s.slice(o.end); this.setCaret(o.start += text.length, o.start); }; new function(){ var d = document, o = d.createElement("input"), s = Selection; s.isStandard = "selectionStart" in o; s.isSupported = s.isStandard || (o = d.selection) && !!o.createRange(); }; }
<form id="form"> <fieldset> <legend>Selection Test</legend> <textarea name="text" rows="10" cols="30"> www.jsfromhell.com Jonas Carlos Lalala Bin Laden x Bush </textarea><br /> <input name="getText" type="button" value="[Get selected text]" /> <input name="getSel" type="button" value="[Get cursor]" /> <br /><input name="setText" type="button" value="[Set selected text]" /> <input name="setSel" type="button" value="[Set cursor]" /> </fieldset> </form> <script type="text/javascript"> var f = document.forms.form; var selection = new Selection(f.text); f.getText.onclick = function(){ alert(selection.getText()); f.text.focus(); }; f.setText.onclick = function(){ var s = prompt("New text:", selection.getText()); s !== null && selection.setText(s); f.text.focus(); }; f.getSel.onclick = function(){ var s = selection.getCaret(); alert("Start: " + s.start + "\nEnd: " + s.end); f.text.focus(); }; f.setSel.onclick = function(){ var s = selection.getCaret(); selection.setCaret(+prompt("Start:", s.start) || 0, +prompt("End:", s.end) || 0); f.text.focus(); }; </script>
function selectfield($optionsarray, $selected = "") { $returnval = ""; foreach ($optionsarray as $field=>$value) { if ($field == $selected) { $returnval .= "<option selected value='" . $field . "'>" . $value . "</option>\n"; } else { $returnval .= "<option value='" . $field . "'>" . $value . "</option>\n"; } } return $returnval; }
---Get next ID number DECLARE @ID int IF (SELECT count(*) FROM @TableName ) > 0 BEGIN SELECT @ID = max(ColumnName ) from @TableName SET @ID = @ID + 1 END ELSE BEGIN SET @ID = 1 END
<script language="JavaScript" type="text/javascript"> <!-- var count1 = 0; var count2 = 0; function insertOptionBefore(num) { var elSel = document.getElementById('selectX'); if (elSel.selectedIndex >= 0) { var elOptNew = document.createElement('option'); elOptNew.text = 'Insert' + num; elOptNew.value = 'insert' + num; var elOptOld = elSel.options[elSel.selectedIndex]; try { elSel.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE } catch(ex) { elSel.add(elOptNew, elSel.selectedIndex); // IE only } } } function removeOptionSelected() { var elSel = document.getElementById('selectX'); var i; for (i = elSel.length - 1; i>=0; i--) { if (elSel.options[i].selected) { elSel.remove(i); } } } function appendOptionLast(num) { var elOptNew = document.createElement('option'); elOptNew.text = 'Append' + num; elOptNew.value = 'append' + num; var elSel = document.getElementById('selectX'); try { elSel.add(elOptNew, null); // standards compliant; doesn't work in IE } catch(ex) { elSel.add(elOptNew); // IE only } } function removeOptionLast() { var elSel = document.getElementById('selectX'); if (elSel.length > 0) { elSel.remove(elSel.length - 1); } } //--> </script>
<form> <input type="button" value="o" onclick="insertOptionBefore(count1++);" /> Insert Before Selected<br /> <input type="button" value="o" onclick="removeOptionSelected();" /> Remove Selected<br /> <select id="selectX" size="10" multiple="multiple"> <option value="original1" selected="selected">Orig1</option> <option value="original2">Orig2</option> </select> <br /> <input type="button" value="o" onclick="appendOptionLast(count2++);" /> Append Last<br /> <input type="button" value="o" onclick="removeOptionLast();" /> Remove Last </form>