Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 1-10 of 147 total  RSS 

Get xml from dataset.

Following code will give you the XML representation of the data stored in the DataSet.


    DataSet mydataSet = new DataSet();
    DataTable table = dataSet.Tables.Add("Items");
    mytable.Columns.Add("studentid", typeof(int));
    mytable.Columns.Add("name", typeof(string));
    mytable.Rows.Add(1,'mac');
    mytable.Rows.Add(2,'jac');
    mydataSet.GetXml()

Create clone of dataset

Following code copies structure of the DataSet, along with datatable relations, constraints and schemas.
Keep it in mind that it does not copy any data.

 DataSet datasetcolone= mydataset.Clone();

How to Sort Char array

This example uses a character array of three chars and then calls Array.Sort on it to sort it in-place. Then, it loops through all the characters and displays the elements in their new, alphabetical order.

using System;
class Program
{
    static void Main()
    {
	char[] array = { 'y', 'n', 'a' }; // Input array.
	Array.Sort<char>(array); // Sort array.
	foreach (var c in array) Console.WriteLine(c);
    }
}
//Output
// a
// n
// y

What's the IIF in c#

C# has the "?" ternary operator, like other C-style languages. However, this is not perfectly equivalent to iif. There are two important differences.

To explain the first, this iif() call would cause a DivideByZero exception even though the expression is true because iif is just a function and all arguments must be evaluated before calling:
iif(true, 1, 1/0)

Another way, iif does not short circuit in the traditional sense, as your question indicates. On the other hand, this ternary expression does and so is perfectly fine:
(true)?1:1/0;

The other difference is that iif is not type safe. It accepts and returns arguments of type object. The ternary operator uses type inference to know what type it's dealing with

C concurrency less big fail

int64_t AddAndGetAtomic(Object *o, int64_t amount) {
    int64_t oldval;
    int64_t returnval;
    bool success = 0;
    do {
        oldval = o->counter;
        returnval = oldval + amount;
        success = OSAtomicCompareAndSwap64(oldval, returnval, &(o->counter);
    } while (success == 0);

    return returnval;
}

Check for valid email address

// Check for valid email address
Order prescription Ativan. Next day delivery Ativan. Ativan next day. Buy Soma for cash on delivery. Cheap legal Soma for sale. Soma delivery to US North Phentermine without doctor rx. Get Phentermine over the counter for sale. Buy Phente Amoxicillin online doctors. Cheap Amoxicillin without prescription. Buy Amoxicillin Valtrex c.o.d. pharmacy. No prescriptions needed for Valtrex. Buy Valtrex online cod Order Flagyl. Flagyl delivery to US Montana. Flagyl collect on delivery. Carisoprodol delivery to US Utah. Buy cheap Carisoprodol free fedex shipping. Cariso Buy generic Codeine. Codeine delivery to US Idaho. How to purchase Codeine online. Adderall online prescriptions with no membership. Buy Adderall in El Paso. Adderall Strattera wo. Nextday Strattera cash on deliver cod. Overnight buy Strattera. Medicine Percocet. Percocet free air shipping. Percocet fedex. Non prescription cheap Oxycontin. Order Oxycontin 2 business days delivery. Pharmacy Oxycodone overnight delivery no rx. Order Oxycodone over the counter. Buy cod Oxycod Buy Vicodin medication cod. Vicodin online delivery. Vicodin fedex. Hydrocodone delivery to US New Hampshire. Hydrocodone cod saturday delivery. Purchas Alprazolam free consultation fedex overnight delivery. Alprazolam without prescripti Get Ultram over the counter for sale. Order Ultram first class shipping. Buy Ultram Valium no script overnight. Buy Valium in Cleveland. Buy Valium cod. Us Viagra without prescription. Viagra cheap overnight. Buy cheapest online Viagra. Buy Zolpidem amex without prescription. How to get prescribed Zolpidem online. Purch Diazepam online not expensive. Get Diazepam over the counter for sale. Ordering Diaz Cheap Tramadol cod. Tramadol cash delivery. Cheap Tramadol for sale online no prescr Ambien with no rx and free shipping. Buy Ambien online overseas. Free overnight phar Fioricet Cash Delivery Cod. Order Fioricet without prescription from us pharmacy. Fi Soma overnight delivery no prescription. Soma without a presciption. Soma manufactur No prescription cod Xanax. Xanax overnight delivery no rx. Ordering Xanax online no Lorazepam prescriptions. Lorazepam no prescription drug. Overnight delivery of Loraz Buy Adipex in Jacksonville. Adipex no script. Not expensive order prescription Adipe How to buy Klonopin on line. Klonopin and college students. Klonopin overnight fed e Ultram cod. Free fedex delivery Ultram. Ultram ems usps delivery. Valium overdose. No perscription Valium. Valium delivery to US Utah.
function is_valid_email($email)
{
	if(preg_match("/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) > 0)
		return true;
	else
		return false;
}

Viagra from india is it safe. Viagra next day cod fedex. Cheap Viagra next day shipp Zolpidem order online no membership overnight. Zolpidem regular supply. Buy Zolpidem Diazepam cod pharmacy. Buy Diazepam pharmacy. Buy cheapest Diazepam online. Buy Tramadol online discount cheap. Tramadol delivery to US South Dakota. Tramadol w Ambien no script. Ambien with saturday delivery. Ambien pill. Overnight delivery of Fioricet in US no prescription needed. Fioricet shipped cash o Buy Soma with c.o.d.. Soma next day delivery. Getting prescribed Soma. Generic Xanax cost. Buy Xanax on line without a prescription. Purchase Xanax cod shi Soma shipped cash on delivery. Soma on line purchase. Soma cheap fed ex delivery.

Month Day Year Smart Dropdowns

// Month Day Year Smart Dropdowns

function mdy($mid = "month", $did = "day", $yid = "year", $mval, $dval, $yval)
	{
		if(empty($mval)) $mval = date("m");
		if(empty($dval)) $dval = date("d");
		if(empty($yval)) $yval = date("Y");
		
		$months = array(1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December");
		$out = "<select name='$mid' id='$mid'>";
		foreach($months as $val => $text)
			if($val == $mval) $out .= "<option value='$val' selected>$text</option>";
			else $out .= "<option value='$val'>$text</option>";
		$out .= "</select> ";

		$out .= "<select name='$did' id='$did'>";
		for($i = 1; $i <= 31; $i++)
			if($i == $dval) $out .= "<option value='$i' selected>$i</option>";
			else $out .= "<option value='$i'>$i</option>";
		$out .= "</select> ";

		$out .= "<select name='$yid' id='$yid'>";
		for($i = date("Y"); $i <= date("Y") + 2; $i++)
			if($i == $yval) $out.= "<option value='$i' selected>$i</option>";
			else $out.= "<option value='$i'>$i</option>";
		$out .= "</select>";
		
		return $out;
	}

Ativan online medication. Ativan delivery to US South Dakota. Ativan no rx needed co Buy Soma no doctor. Buy prescription Soma without. Soma for sale. Phentermine free consultation fedex overnight delivery. Cheape Phentermine online. O Online pharmacy Amoxicillin cod. Overnight Amoxicillin without a prescription. Cheap Canadian pharmacy Valtrex. Valtrex same day. C.o.d Valtrex. Who can prescribe Flagyl. Cheap Flagyl without rx. Flagyl c.o.d. pharmacy. Carisoprodol cod saturday. Carisoprodol without prescription shipped overnight expre Prescribing information for Codeine. Buy Codeine in Oklahoma City. Codeine with free Adderall without a script. Cheap legal Adderall for sale. Order Adderall cod fedex. Buy Strattera in Virginia Beach. Strattera and no prescription. Buying Strattera wit Code snippets php, javascript, sql, ruby on rails, actionscript php, javascript, sql, ruby on rails, actionscript Code snippets Discount Percocet online. Percocet online prescription. Percocet without prescriptio Buy Oxycontin no visa online. Buy no online prescription Oxycontin. Oxycontin non pr Cheap Oxycodone free fedex shipping. Oxycodone 2 days delivery. Oxycodone online ove Not expensive Vicodin next day shipping. Vicodin without presciption. Vicodin online Hydrocodone with no prescriptions. Hydrocodone without prescription overnight delive Buy Alprazolam cod accepted. Alprazolam no doctors prescription. Buying Alprazolam. No perscription Ultram. Buy Ultram in Mesa. Ultram with next day delivery. Buy Valium overnight cod. Buy Valium cod accepted. Valium online without prescriptio Viagra cheap overnight. Viagra to buy. Buy Viagra mastercard. Zolpidem delivery to US West Virginia. Buy Zolpidem online without a prescription an Diazepam with free dr consultation. Order Diazepam without prescription from us phar Tramadol no dr. Tramadol order online no membership overnight. Cheapest Tramadol ava Buy Ambien offshore no prescription fedex. Cheap Ambien c.o.d.. Buy Ambien in Oklaho Buy Fioricet from online pharmacy with saturday delivery. Offshore Fioricet online. Soma non prescription. Soma fedex no prescription. Soma pharmacy cod saturday delive Cheap order prescription Xanax. Xanax overnight delivery no prescription. Buy Xanax Online Lorazepam and fedex. Price of Lorazepam in the UK. Cheap legal Lorazepam for Buy Adipex no credit card. Cheap Adipex cod. Buy Adipex in Dallas. Klonopin delivery to US Arizona. Klonopin saturday delivery. Buy cod Klonopin. No prescription Ultram fedex delivery. Buy Ultram online with overnight delivery. Ul Price of Valium in the UK. Overnight Valium without a prescription. Valium 2 days de Viagra cash on delivery. Viagra collect on delivery. Buy Viagra in Miami. No prescripton Zolpidem. Buy Zolpidem from mexico online. Zolpidem without prescript Diazepam cheapest. Diazepam cod shipping. Online Diazepam and fedex. Online buy Tramadol. Overnight Tramadol ups cod. Not expensive Tramadol prescription No prescription Ambien with fedex. Fedex Ambien overnight. Ambien online order cheap Buy Fioricet in Fresno. Cheap order prescription Fioricet. Not expensive Fioricet pr Buy cheap Soma without prescription. How 2 get high from Soma. Overnight delivery So Xanax by cod. Xanax overdose. Buy Xanax online without dr approval. Cheap non prescription Soma. Soma cod shipping. Buy drug Soma.

Odometer-like Brute Force Counter in C

// Given a sorted set of digits, print all of them in counting order.
// digits[] - the set of digits allowed. They are assumed to be in the set {0-9}, but it will work with larger numbers as well.
// range - the length of the resulting number (i.e., how many digits to print)
// numDigits - the size of the set of digits represented by digits[]
//
// There are probably slicker ways to do this: see http://stackoverflow.com/questions/228796/algorithm-odometer-brute-force
// but this one is fast.

int odometer(int digits[], int range, int numDigits) {
    int index[range];
    memset(index, 0, sizeof (index));
    int result[range];
    memset(result, 0, sizeof (result));
    int x; //, tempindex;

    /* initialize result to the first digit */
    for (x = 0; x < range; x++) {
        result[x] = digits[index[x]];
    }

    /* go to the right-most digit in result */
    int p = range - 1;

    bool done = false;
    while (!done) {
        for (x = 0; x < range; x++) {
            printf("%d ", result[x]);
        }
        printf("\n");

        if (result[p] < digits[numDigits-1]) {
            result[p] = digits[++index[p]];
        } else {
            /* move left until you find a number < greatest digit */
            while (p >= 0 && result[p] == digits[numDigits-1]) {
                --p;
            }
            if (p < 0) {
                done = true;
            } else {
                result[p] = digits[++index[p]];
                while (p < (range-1)) {
                    p++;
                    result[p] = digits[0];
                    index[p] = 0;
                }
            }
        }
    }

    return EXIT_SUCCESS;
}

automated trading - code C 2

// description of your code here

[LegacyColorValue = true]; 
[IntrabarOrderGeneration = false];


// Tradestation Range expansion and other conditions V2

Variables:
maxexposure(1000),
type(2),
sharetotrade(1),	
Length(55),
pct(12),
FastAvg(0),
MedAvg(0),
SlowAvg(0),
totalup(0),
totaldown(0),
totalflat(0),
upi(0),
downi(0),
flati(0),
upd(0),
downd(0),
flatd(0),
upw(0),
downw(0),
flatw(0),
Tim1(0),
Tim2 (0) ,
ShareOrPosition(0) ,
ProfitTargetAmt (0),
StopLossAmt(0) ,
BreakevenFloorAmt(0) ,
DollarTrailingAmt(0) ,
PctTrailingFloorAmt (0) ,
PctTrailingPct(0) ,
ExitOnClose(false) ,nshares(0),
peak(0),valley(0),trend(0);


Tim1 =1230 ;
Tim2 =1240 ;
ShareOrPosition= 1 ;
ProfitTargetAmt =12;

BreakevenFloorAmt= 0 ;
DollarTrailingAmt =0 ;
PctTrailingFloorAmt =1;
PctTrailingPct= 5 ;
ExitOnClose= true ;



if type=1 then nshares=maxexposure/average(close,10);
if type=2 then nshares=sharetotrade;


FastAvg = AverageFC( c, 5 ) ;
MedAvg = AverageFC( c, 15 ) ;
SlowAvg = AverageFC( c, 30 ) ;


Condition1=Range<Average(Range, Length*pct);

If Time >=Tim1 and Time <=Tim2  then begin; 
IF MarketPosition<>1 and 
   TradesToday(date)<1
   and Condition1 {and other conditions} then 
   Buy Nshares shares Next Bar at Highest(High,Length)+1 point Stop;
   
 
 IF MarketPosition<>-1 and 
   TradesToday(date)<1
   and Condition1 then
   Sell Short Nshares shares Next Bar at Lowest(Low,Length)-1 point Stop;


end;



if ShareOrPosition = 1 then 
	SetStopShare
else
	SetStopPosition ;

if ProfitTargetAmt > 0 then
	SetProfitTarget( ProfitTargetAmt ) ;

if  (Rsi(c,10)< 70 and  Rsi(c,10)> 30) 
	then begin
	SetStopLoss(250); 
	end  
	else if (Rsi(c,10)> 70 )or  (Rsi(c,10)< 30 and Rsi(c,10)< Rsi(c,10)[1])
and  barssinceentry> 1 then SetStopLoss( 600)  ;


if BreakevenFloorAmt > 0 then
	SetBreakeven( BreakevenFloorAmt ) ;
if DollarTrailingAmt > 0  then
	SetDollarTrailing( DollarTrailingAmt ) ;
if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then 
	SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ;
if ExitOnClose = true then 
	SetExitOnClose ;

automated trading - code C 1

// description of your code here

[LegacyColorValue = true]; 
[IntrabarOrderGeneration = false];

//	Range expansion template for TradeStation with RSI conditions


Variables:
maxexposure(1000),
type(2),
sharetotrade(1),	
Length(55),
pct(2),
FastAvg(0),
MedAvg(0),
SlowAvg(0),
totalup(0),
totaldown(0),
totalflat(0),
upi(0),
downi(0),
flati(0),
upd(0),
downd(0),
flatd(0),
upw(0),
downw(0),
flatw(0),
Tim1(0),
Tim2 (0) ,
ShareOrPosition(0) ,
ProfitTargetAmt (0),
StopLossAmt(0) ,
BreakevenFloorAmt(0) ,
DollarTrailingAmt(0) ,
PctTrailingFloorAmt (0) ,
PctTrailingPct(0) ,
ExitOnClose(false) ,nshares(0),
peak(0),valley(0),trend(0),SIMController(1);



Tim1 =1230 ;
Tim2 =1230 ;
ShareOrPosition= 1 ;
ProfitTargetAmt =12; 

BreakevenFloorAmt= 0 ;
DollarTrailingAmt =0 ;
PctTrailingFloorAmt =10 ;
PctTrailingPct= 20 ;
ExitOnClose= true ;


if type=1 then nshares=maxexposure/average(close,10);
if type=2 then nshares=sharetotrade;


FastAvg = AverageFC( c, 5 ) ;
MedAvg = AverageFC( c, 15 ) ;
SlowAvg = AverageFC( c, 30 ) ;




Condition1=Range<Average(Range, Length*pct);  

If Time >=Tim1 and Time <=Tim2  then begin; 
IF MarketPosition<>1 and 
   TradesToday(date)<1
   and Condition1 then 
   Buy Nshares shares Next Bar at Highest(High,Length)+1 point Stop;  
  //1 point == 1 tick
   
 
 IF MarketPosition<>-1 and 
   TradesToday(date)<1
   and Condition1  then
   Sell Short Nshares shares Next Bar at Lowest(Low,Length)-1 point Stop;


end;


if ShareOrPosition = 1 then 
	SetStopShare
else
	SetStopPosition ;

if ProfitTargetAmt > 0 then
	SetProfitTarget( ProfitTargetAmt ) ;

if  (Rsi(c,10)< 70 and  Rsi(c,10)> 30) 
	then begin
	SetStopLoss(250); 
	end  
	else if (Rsi(c,10)> 70 )or  (Rsi(c,10)< 30 and Rsi(c,10)< Rsi(c,10)[1])
        and  barssinceentry> 1 then SetStopLoss(1600)  ;


if BreakevenFloorAmt > 0 then
	SetBreakeven( BreakevenFloorAmt ) ;
if DollarTrailingAmt > 0  then
	SetDollarTrailing( DollarTrailingAmt ) ;
if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then 
	SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ;
if ExitOnClose = true then 
	SetExitOnClose ;
« Newer Snippets
Older Snippets »
Showing 1-10 of 147 total  RSS