Skip to content

Instantly share code, notes, and snippets.

View arviman's full-sized avatar

Arvind Balasubramaniam arviman

View GitHub Profile
DECLARE @proc varchar(255), @dynamicSql varchar(255), @ParamDefinition varchar(255), @Actor1 nvarchar(255),@Actor2 nvarchar(255)
SET @proc = 'OnScreenChemistry'
--*cursor declare/fetch stuff*
--set @Actor1, @Actor2 values here from your cursor
--create your query with placeholders for the parameters to your stored proc
SET @dynamicSql = 'exec ' + @proc + '@Actor1Param,@Actor2Param,@ResultParam output'
--create definitions for your parameter placeholders
Set @ParamDefinition = '@Actor1Param nvarchar(255) ,@Actor2Param nvarchar(255), @ResultParam float(53) output'
SET @dynamicSql = 'exec ' + @proc + ' ''' + @Actor1 + ''', '''+@Actor + ''''
EXECUTE sp_ExecuteSQL @dynamicSql
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<ul id="navi">
</HeaderTemplate>
<ItemTemplate>
<li>
<a href='<%#DataBinder.Eval(Container.DataItem, "ArticleURL")%>'>
<%#DataBinder.Eval(Container.DataItem, "Name")%>
</a>
<table>
<tr><td>
<asp:PlaceHolder ID="plcPaging" runat="server" >
<asp:LinkButton ID="prevLnk" Text = "Prev" runat="server" OnClick="prev_Click"/>
<asp:Label ID="prevspacer" Text = " " runat="server" />
<asp:LinkButton ID="lnkPage1" Text = "1" runat="server" OnClick="lnk_Click"/>
<asp:Label ID="spacer1" Text = " | " runat="server" />
<asp:LinkButton ID="lnkPage2" Text = "2" runat="server" OnClick="lnk_Click"/>
<asp:Label ID="spacer2" Text = " | " runat="server" />
private int itemsPerPage = 2;
private CurrentProperties _CurrentProps = new CurrentProperties();
[Serializable()]
private struct CurrentProperties
{
public int RowCount;
public int CurrentPage;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
LoadData(itemsPerPage, 0);
}
private void LoadData(int take, int pageSize)
{
//somehow return all the objects you need. could be a datatable instead of a list of objects
List articles = GetAllItems();
//set total item count
RowCount = articles.Count;
var topDocs = (from c in articles select c).Skip(pageSize).Take(take);
PagedDataSource pagedSrc = new PagedDataSource();
pagedSrc.DataSource = topDocs;
protected void LoadItemsBasedOnCurrentPage()
{
int take = CurrentPage * itemsPerPage;
int skip = CurrentPage == 1 ? 0 : take - itemsPerPage;
LoadData(take, skip);
}
protected void prev_Click(object sender, EventArgs e)
{
LinkButton lnk = sender as LinkButton;
CurrentPage--;
/// <summary>
/// sets the paging control's properties
/// </summary>
protected void FormatPagingControl()
{
//number of page links
int n = 4;
int lastpage = ((RowCount -1) / itemsPerPage) + 1;
int startPage = CurrentPage;
int lastPageToDisplay = Math.Min(lastpage, startPage + (n-1));
@arviman
arviman / clocks.java
Last active December 14, 2015 19:29
USACO clocks problem - solved using BFS and bit masks in java
import java.io.*;
import java.util.*;
class Node
{
int state;//current state of clocks
byte[] moves;//past moves done
public Node(int state, byte[] oldMoves, Byte lastMove)
{