This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringHashCodeExtensions | |
{ | |
public static int GetHashCodeJava(this string value) | |
{ | |
if (value == null) | |
throw new ArgumentNullException("value"); | |
int hashCode = 0; | |
for (int i = 0; i < value.Length; i++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Algorithms.Maths | |
{ | |
public struct Queen | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static bool CheckAccountNumber(string bankNumber, string accountNumber) | |
{ | |
int[] mask = new[] { 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1 }; | |
if (bankNumber.Length < 3) | |
{ | |
Console.WriteLine("Incorrect bank number."); | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Program { | |
val testText = "The quick brown fox jumps over a lazy dog." | |
val testPattern = "fox * over" | |
def main (args: Array[String]) { | |
println( | |
s""" | |
|Text: $testText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CircularQueue | |
{ | |
// Motivation: | |
// | |
// We do not store count of items in the queue to avoid mutual blocking of enqueue and dequeu operaions. | |
// In the current implementation enqueue and dequeue do not block each other, | |
// but simultaneous calls of the same operations will be blocking. | |
// | |
// Alos we allocate array with size N + 1 to the logical capacity of the queue N, | |
// this is made to distinguish between cases when the queue is empty or full |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StateSwitch | |
{ | |
private readonly Action enterAction; | |
private readonly Action leaveAction; | |
private readonly bool leaveOnSuspend; | |
private uint counter; | |
private bool entered; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class LinkedListExtensions | |
{ | |
public static T Last<T>(this IEnumerable<T> items, int index) | |
{ | |
T[] keepItems = new T[index]; | |
int position = 0; | |
int count = 0; | |
foreach (var item in items) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static async Task FailsAsync(bool shouldFail) | |
{ | |
if (shouldFail) | |
throw new ApplicationException("Custom exception."); | |
await Task.CompletedTask; | |
} | |
static Task Fails(bool shouldFail) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$n = 100; $sum = 0; for ($i=0; $i -lt $n; $i++) { $sum = $sum + (Measure-Command -Expression { Invoke-WebRequest -Uri $url }).Milliseconds }; $sum / $n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Reflection | |
let getMethod (bindingFlags: BindingFlags) (methodName: string) (t: Type): MethodInfo option = | |
if t <> null then | |
Some (t.GetMethod(methodName, bindingFlags)) | |
else | |
None | |
let privateMethod (methodName: string) (t: Type) = |
OlderNewer