Skip to content

Instantly share code, notes, and snippets.

@rajrao
rajrao / button.py
Created August 1, 2016 02:46 — forked from ecaron/button.py
Python script for listening to Raspberry Pi button push
import requests
import time
import RPi.GPIO as GPIO
url = 'http://nightlight/' # I map this to my internal DNS hosting the node app
gpio_pin=18 # The GPIO pin the button is attached to
longpress_threshold=5 # If button is held this length of time, tells system to leave light on
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

Hello World

@rajrao
rajrao / lz77.cs
Created July 4, 2020 14:28 — forked from mjs3339/lz77.cs
C# Implementation LZ77 Compression Algorithm
public static class Lz77
{
private const int RingBufferSize = 4096;
private const int UpperMatchLength = 18;
private const int LowerMatchLength = 2;
private const int None = RingBufferSize;
private static readonly int[] Parent = new int[RingBufferSize + 1];
private static readonly int[] LeftChild = new int[RingBufferSize + 1];
private static readonly int[] RightChild = new int[RingBufferSize + 257];
private static readonly ushort[] Buffer = new ushort[RingBufferSize + UpperMatchLength - 1];
@rajrao
rajrao / OdataQueryD365FinanceAndOperationsTest.cs
Last active September 14, 2020 03:43
Shows how to perform authentication and retrieval of data from D365 Finance and Operations using OData and the Service to service calls using client credentials
//more details at: https://blog.aggregatedintelligence.com/2020/09/d365-finance-and-operations-odata-query.html
var baseUrl = "https://myDomain.sandbox.operations.dynamics.com"; //a trailing slash here will cause a "No P3P Policy defined" error
var tenantId = "TENANTID AS A GUID HERE";
string applicationId = "APPLICATION GUID HERE";
string clientSecret = "CLIENT SECRET HERE";
string api = "data/";
var authorityUrl = $"https://login.windows.net/{tenantId}";
//Add the following launch configuration to launch.json. I create
//a specific launch.json in my workspace folder as this setting
//will likely be different for each workspace folder.
//change the "startupFileNameHere" to point to your startup file.
"configurations": [
{
"name": "Python: Run Startup File",
"type": "python",
"request": "launch",
//validates a cloud formation template in VsCode.
//add this to a file named tasks.json in the .vscode folder.
//to run: Terminal >> Run Task...
{
"version": "2.0.0",
"tasks":[
{
"label":"aws cf validate-template",
"type":"shell",
"presentation": {
#based on: https://www.therealomar.com/articles/2019-06/Git-the-most-edited-files-in-a-project
git log --pretty=format: --name-only --since=1.years.ago |
Where-Object { ![string]::IsNullOrEmpty($_) } |
Group-Object |
Sort-Object -Property Count -Descending |
Select-Object -Property Count, Name -First 10
#This code is an example of how to use text based mapper class names to query the airflow db.
import inspect
import re
from airflow.models.base import Base
from airflow import DAG, settings
from airflow.operators.python import PythonOperator
from airflow.utils.dates import days_ago
#BAD
import os
class SlackLogger:
def post message(self, message):
print("I'm posting to Slack: (message)")
#in your code e.g. Celery jobs
'''
if os.getenv("APP_ENVIRONMENT") == "production":