Skip to content

Instantly share code, notes, and snippets.

@ugnb
ugnb / Program.cs
Created November 12, 2018 13:50
Execute external program (nslookup) in c# asynchronously to resolve domain MX records.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace DNSResolve
{
class Program
{
public static async Task Main(string[] args)
{
@ugnb
ugnb / bitbucket-pipelines.yml
Last active November 21, 2018 12:01
DotNet Core tests reporting with JUnitTestLogger in Bitbucket Pipelines
image: microsoft/dotnet:2.1-sdk-alpine
pipelines:
default:
- step: &testsStep
name: Tests
caches:
- dotnetcore
script:
- export PROJECT_NAME=relative/path/to/tests/project
@ugnb
ugnb / serverless.yml
Last active October 7, 2018 13:33
'Serverless' Framework config for NodeJS that removes development dependencies before deploy. (Requires zip and unzip installed)
service: my-service-name
provider:
name: aws
runtime: nodejs8.10
region: us-east-1
environment:
NODE_ENV: ${self:custom.stage}
custom:
stage: ${opt:stage, self:provider.stage}
@ugnb
ugnb / bulk_update.sql
Created December 11, 2017 17:05
Postgres bulk update records
UPDATE table_name
SET (column1, column2, column3) =
(
data_table.column1,
data_table.column2,
data_table.column3
)
FROM (
SELECT
unnest(array[@Column1Values]) as column1,
@ugnb
ugnb / insert_on_conflict_update.sql
Created December 2, 2017 02:40
Postgresql: Update row with insertion values in case of conflict
INSERT INTO table1
(id, column1, column2, column3)
VALUES
(:id, :column1, :column2, :column3)
ON CONFLICT (id) DO UPDATE
SET
column1 = EXCLUDED.column1,
column2 = EXCLUDED.column2,
column3 = EXCLUDED.column3;
@ugnb
ugnb / boto3_digitalocean.py
Last active November 24, 2023 16:52
Using Python boto3 with DigitalOcean object storage
import logging
import urllib.request
import boto3
from settings import OBJECT_STORAGE_KEY, OBJECT_STORAGE_SECRET, OBJECT_STORAGE_REGION, OBJECT_STORAGE_BUCKET
logger = logging.getLogger(__name__)
s3config = {
"region_name": OBJECT_STORAGE_REGION,
"endpoint_url": "https://{}.digitaloceanspaces.com".format(OBJECT_STORAGE_REGION),
@ugnb
ugnb / extract_urls.py
Created March 31, 2017 12:45
A faster way to extract all URLs from page using Selenium WebDriver in Python
import json
from json import JSONDecodeError
from typing import List
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
driver = webdriver.Remote(
command_executor='{}/wd/hub'.format('http://localhost:4444'),
desired_capabilities=webdriver.ChromeOptions().to_capabilities(),
@ugnb
ugnb / main.cpp
Last active August 17, 2016 18:30
Using DallasTemperature lib for 1-wire DS18B20 thermometer with Arduino timer interrupt on ESP8266
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define TEMP_PIN D5
#define TEMP_SENSOR_PRECISION 8
#define TEMP_INTERRUPT_CYCLES ESP.getCycleCount() + 50000000
// Change this to your sensor address
#define TEMP_SENSOR_ADDR {0x28, 0x35, 0x33, 0xB3, 0x06, 0x00, 0x00, 0x1A}