Skip to content

Instantly share code, notes, and snippets.

private void ExecutingOnANewThread()
{
//both tasks defined bellow will be executed on a new background thread
var task = new Task(() => { }, TaskCreationOptions.LongRunning);
task.Start(TaskScheduler.Default);
//or
var task2 = Task.Factory.StartNew(() => { }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
@CosminLazar
CosminLazar / RavenDBExtensions.cs
Created May 19, 2014 10:17
Extension class adding FirstOrDefaultLazy to RavenDB
public static class RavenDBExtensions
{
public static Lazy<T> FirstOrDefaultLazy<T>(this IQueryable<T> query, Func<T, bool> predicate)
{
if (query == null) throw new ArgumentNullException("query");
if (predicate == null) throw new ArgumentNullException("predicate");
return query.Where(x => predicate(x)).FirstOrDefaultLazy();
}
@CosminLazar
CosminLazar / WrongInstall.ps1
Created February 21, 2015 21:25
How not to modify the project from Install.ps1
#This script edits the project file and marks the talkfx-c.dll files to always be copied to the output directory
param($installPath, $toolsPath, $package, $project)
# Load project XML.
$doc = New-Object System.Xml.XmlDocument
$doc.Load($project.FullName)
$namespace = 'http://schemas.microsoft.com/developer/msbuild/2003'
# Find the node containing the file. The tag "Content" may be replace by "None" depending of the case, check your .csproj file.
$talkFXDlls = Select-Xml "//msb:Project/msb:ItemGroup/msb:Content[contains(@Include, 'talkfx-c.dll')]" $doc -Namespace @{msb = $namespace}
$x86TalkFX = $project.ProjectItems.Item("CroccatTalkWrapper").ProjectItems.Item("win32-x86").ProjectItems.Item("talkfx-c.dll");
$x86TalkFX.Properties.Item("BuildAction").Value = [int]2;
Install-Package NuGetDebugTools
Add-Debugger.ps1
Set-PSBreakpoint -Command init.ps1, install.ps1, uninstall.ps1
#pragma once
#define TALKFX_ZONE_AMBIENT 0x00
#define TALKFX_ZONE_EVENT 0x01
#define TALKFX_EFFECT_OFF 0x00
#define TALKFX_EFFECT_ON 0x01
#define TALKFX_EFFECT_BLINKING 0x02
#define TALKFX_EFFECT_BREATHING 0x03
#define TALKFX_EFFECT_HEARTBEAT 0x04
public interface IHaveDeferredEnumerable
{
IEnumerable<IHaveDeferredEnumerable> Get();
}
public class HasDeferredEnumerable : IHaveDeferredEnumerable
{
public IEnumerable<IHaveDeferredEnumerable> Get()
{
yield return null;
#include <DHTSensor.h>
DHTSensor sensor(3);//Will be using pin3 for collecting the data
void loop()
{
DHTSensorMeasurement re = sensor.Read();
if (!re.HasError())
{
Serial.print("H: ");
Serial.print(re.Humidity());
Serial.print(" T: ");
@CosminLazar
CosminLazar / mosquitto.service
Created October 19, 2018 18:33
Systemd service for Mosquitto
[Unit]
Description=Mosquitto MQTT Broker daemon
ConditionPathExists=/etc/mosquitto/mosquitto.conf
After=network.target
Requires=network.target
[Service]
Type=forking
RemainAfterExit=no
StartLimitInterval=0
Connect to a bluetooth speaker
sudo bluetoothctl
power on
pairable on
agent on
default-agent
scan on
pair xx:xx:xx:xx:xx:xx
trust xx:xx:xx:xx:xx:xx