Skip to content

Instantly share code, notes, and snippets.

void MergeListImproved(ref List<int> list1, List<int> list2)
{
int list1Size = list1.Count;
int list2Size = list2.Count;
int totalSize = list1Size + list2Size;
var newList = new List<int>(totalSize);
int index1 = 0;
int index2 = 0;
void MergeList(ref List<int> list1, List<int> list2)
{
int list1Size = list1.Count;
int list2Size = list2.Count;
int totalSize = list1Size + list2Size;
list1.Capacity = totalSize;
int index1 = 0;
int index2 = 0;
using System.Threading.Tasks;
static void SleepThenPrintSquare(int n) {
Thread.Sleep(2000);
Console.WriteLine("{0}", n * n);
}
static void Main() {
var tasks = new List<Task>(5);
using System.Threading.Tasks;
static void SleepThenPrintSquare(int n) {
Thread.Sleep(2000);
Console.WriteLine("{0}", n * n);
}
static void Main() {
var tasks = new List<Task>(5);
@luuhq
luuhq / redirect.scala
Created June 14, 2012 05:47
Play framework redirect
val newID = Inventory.save(data)
Redirect(
controllers.routes.Inventory.index.toString +
"#record_%d".format(newID)
).flashing("success" -> "Insertion succeeded!")
val lnOf2 = scala.math.log(2) // natural log of 2
def log2(x: Double): Double = scala.math.log(x) / lnOf2
@luuhq
luuhq / Global.scala
Created May 28, 2012 19:42
Play Framework: Handle URL trailing slash with Application Global
import play.api._
import play.api.mvc._
object Global extends GlobalSettings {
override def onHandlerNotFound(request: RequestHeader): Result = {
// handle trailing slashes
if (request.path.endsWith("/")) {
// construct a new URI without the slash