Skip to content

Instantly share code, notes, and snippets.

View evanricard's full-sized avatar
😟

Evan Ricard evanricard

😟
View GitHub Profile
$dir = dir *.zip
#go through each zip file in the directory variable
foreach($item in $dir)
{
Expand-Archive -Path $item -DestinationPath ($item -replace '.zip','') -Force
}
/* unzip all files in a directory and then do some work!! */
@evanricard
evanricard / Xml.cs
Last active February 11, 2020 22:51
GetXMLValue
private static string GetXmlValue(string id, string getData, XDocument xdoc)
{
return xdoc.Root.Descendants("girl").Elements().
Where(node => node.Name == "id" && node.Value == id).
Single<XElement>().NodesAfterSelf().
Where(values => ((XElement)values).Name == getData).
Cast<XElement>().Single<XElement>().Value;
}
@evanricard
evanricard / EnumerableCollection.cs
Last active February 11, 2020 22:51
CollectAndEnumerate
class Team<T> : IEnumerable<T> // enumerable collection
{
private T[] workers;
private const byte DEFAULTSIZE = 5;
public Team() {
this.workers = new T[DEFAULTSIZE];
}
private int i = 0;
public void Add(T param)
@evanricard
evanricard / DuffsDevice.cs
Last active February 11, 2020 22:51
Loop unrolling
static void DuffsDevice(uint count, int[] A, int[] B)
{
uint i = 0;
uint n = (count + 7) / 8;
switch (count % 8) {
case 0: A[i] = B[i++]; goto case 7;
case 7: A[i] = B[i++]; goto case 6;
case 6: A[i] = B[i++]; goto case 5;
case 5: A[i] = B[i++]; goto case 4;
case 4: A[i] = B[i++]; goto case 3;
@evanricard
evanricard / &.cs
Last active February 11, 2020 22:51
C# pointer #note
&array[0]
[DllImport("kernel32", SetLastError = true)]
static extern unsafe IntPtr CreateFile(
string FileName,
uint DesiredAccess,
uint ShareMode,
uint SecurityAttributes,
uint CreationDisposition,
@evanricard
evanricard / ref return.cs
Last active February 11, 2020 22:47
ref
static void Main()
{
var store = new NumberStore();
WriteLine($"Исходная последовательность: {store.ToString()}");
ref var value = ref store.FindNumber(16);
value *= 2;
WriteLine($"Новая последовательность: {store.ToString()}");
//: 1 3 7 15 31 63 127 255 511 1023
//: 1 3 7 15 62 63 127 255 511 1023
@evanricard
evanricard / disposal.cs
Last active February 11, 2020 22:51
IDisposable
public class Example : IDisposable
{
private IntPtr buffer; // неуправляемый буфер памяти
private SafeHandle resource; // управляемый ресурс
public Example() // конструктор
{
this.buffer = ...
this.resource = ...
}
@evanricard
evanricard / NontrailingNamedArgumentGenericInvoke.cs
Last active February 11, 2020 22:48
NamedGenericNonInvoke #weird
void M(int x, int y) { }
void M<T>(T y, int x) { }
void M2()
{
M(3, 4);
M(y: 3, x: 4); // Invokes M(int, int)
M(y: 3, 4); // Invokes M<T>(T, int)
}
@evanricard
evanricard / WordDoc
Last active October 13, 2019 17:12
werd
Application app = new Application { Visible = true };
Document doc = app.Documents.Add*(;
Paragraph para = doc.Paragraphs.Add();
para.Range.Text = "Simple new code";
doc.SaveAs2<-->(FileName: "demo2.docx");
doc.Close();
app.Application.Quit();
@evanricard
evanricard / Dynamism
Last active February 11, 2020 22:48
dynamic #note
Dynamic typing supports custom behavior via IDynamicMetaObjectProvider and the DynamicObject class
Dynamic typing is implemented with both compiler and framework features. The framework optimizes and caches for efficiency.