Skip to content

Instantly share code, notes, and snippets.

View AlphaGit's full-sized avatar

Alpha AlphaGit

View GitHub Profile
@AlphaGit
AlphaGit / markup.html
Created December 28, 2011 19:26 — forked from tathamoddie/markup.html
One color to rule them all.
<div id="foo"><div class="bar">Baz</div></div>
class ClientA
{
public virtual List<Invoice> Invoices { get; set; }
//...
public Product GetMostBuyedProduct(DateTime from, DateTime to)
{
//...
}
@AlphaGit
AlphaGit / SO.cs
Created February 7, 2012 17:48
StackOverflow on GetEnumerator
public class TableCountryMappingCollection : ConfigurationElementCollection, IList<TableCountryMapping>
{
//...
IEnumerator<TableCountryMapping> IEnumerable<TableCountryMapping>.GetEnumerator()
{
foreach (var item in ((System.Collections.IEnumerable)this).Cast<TableCountryMapping>())
yield return item;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
@AlphaGit
AlphaGit / RandomElement.cs
Created April 16, 2012 14:33
T IEnumerable<T>.RandomElement() extension method
internal static class IEnumerableExtensions
{
private static Random _random = new Random();
public static T RandomElement<T>(this IEnumerable<T> list)
{
var index = _random.Next(list.Count());
return list.ElementAt(index);
}
}
@AlphaGit
AlphaGit / ThreadingClass.cs
Created May 11, 2012 20:13
Testing Threading and parallel tasks in C# 4.5
public class ThreadingClass
{
private static Random rnd = new Random();
public void StartSomeWork()
{
var threadNumber = 0;
var threadStart = new ThreadStart(() =>
{
Thread.CurrentThread.Name = string.Format("Thread {0}", ++threadNumber);
@AlphaGit
AlphaGit / Async.cs
Created May 30, 2012 19:30
Async without async
class Program
{
static void Main(string[] args)
{
long number = 4278;
var t = new Thread(() => FactorNumber(number, FactorizationDone));
t.Start();
t.Join();
Console.ReadKey();
@AlphaGit
AlphaGit / Async.cs
Created May 30, 2012 21:28
Async with async, CPU bound
class Program
{
static void Main(string[] args)
{
StartWork();
Console.WriteLine("Processing is happening right now..");
Console.ReadKey();
}
static async Task StartWork()
@AlphaGit
AlphaGit / mediaqueries.css
Created September 5, 2012 18:28
Media query introduction
@media screen and (max-device-width: 480px) {
menu {
display: none;
}
}
@AlphaGit
AlphaGit / each_with_index.js
Created December 12, 2012 17:56 — forked from burin/each_with_index.coffee
Each block iterator for handlebars.js, supporting a zero-based index property.
// {{#each_with_index records}}
// <li class="legend_item{{index}}"><span></span>{{Name}}</li>
// {{/each_with_index}}
Handlebars.registerHelper("each_with_index", function(array, block) {
var buffer = "";
for (var i = 0, j = array.length; i < j; i++) {
var item = array[i];
// stick an index property onto the item, starting with 0, may make configurable later
<!DOCTYPE html>
<html>
<head>
<title>Arkanoid with canvas</title>
<link rel="stylesheet" type="text/css" href="arkanoid.css">
<script type="text/javascript" src="arkanoid.js"></script>
</head>
<body onload="arkanoid.init();">
</body>
</html>