Skip to content

Instantly share code, notes, and snippets.

View msadowski's full-sized avatar

Mateusz Sadowski msadowski

View GitHub Profile
void fillGlobalVariables()
{
double temp_double;
float temp_float = 0f;
int temp_int;
char c;
...
while()
{
c = serial_read(...); //receive one byte from serial port and put it into c
private void swap(ref int lhs, ref int rhs)
{
int temp = lhs;
lhs = rhs;
rhs = temp;
}
void some_function()
{
float temp_a;
float temp_b;
float temp_c;
//please, kill me
...
}
@msadowski
msadowski / Pair.cs
Created April 17, 2016 12:46
An implementation of Jon Skeet's generic class for Pair<T1,T2> from C# in Depth
using System;
using System.Collections.Generic;
public sealed class Pair<T1, T2> : IEquatable<Pair<T1, T2>>
{
/*
USAGE:
Pair<int, string> myPair = new Pair<int, string>(4, "asd");
Pair<int, string> mySecondPair = new Pair<int, string>(4, "asd");
Pair<int, string> myThirdPair = new Pair<int, string>(4, "asdsds");
import random
import time
while True:
randomInt = random.randint(0,100)
randomNormalized = random.random()
caseLessThenHalf = (randomNormalized < 0.5)
caseEven = ((randomInt % 2) == 0)
caseMoreThanTen = (randomInt > 10)
import random
import time
caseCounter = 0
randomInt = random.randint(0,100)
randomNormalized = random.random()
caseLessThenHalf = (randomNormalized < 0.5)
caseEven = ((randomInt % 2) == 0)
caseMoreThanTen = (randomInt > 10)
@msadowski
msadowski / LambdaEvents.cs
Created June 23, 2016 06:44
Jon Skeet approach for Event Logging using Lambdas
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace testAdvanced
{
class Program
{
static void Main(string[] args)
@msadowski
msadowski / OverlayForm.cs
Created July 24, 2016 07:32
Movable overlay form
using System.Drawing;
using System.Windows.Forms;
namespace BejeweledBot
{
class OverlayForm : Form
{
private int X { get; set; }
private int Y { get; set; }
private bool isDragged = false;
@msadowski
msadowski / ColorIdentification.cs
Last active July 24, 2016 07:59
ColorIdentification
private void setTilesColors(Bitmap bmp)
{
int offset = TileWidth / 3;
for (int row = 0; row < boardRows; row++)
for(int col = 0; col < boardColumns; col++)
{
int x = corner.X + row * TileWidth + offset;
int y = corner.Y + col * TileWidth + offset;
Rectangle cloneRect = new Rectangle(x, y, TileWidth - 2 * offset, TileWidth - 2 * offset);
PixelFormat format = bmp.PixelFormat;
static class ScreenCap
{
public static Bitmap Grab(Rectangle rect)
{
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(rect.X,
rect.Y,
0, 0,