Skip to content

Instantly share code, notes, and snippets.

View greglangford's full-sized avatar

Greg Langford greglangford

View GitHub Profile
@greglangford
greglangford / main.c
Created July 10, 2023 21:58
very dirty mbedtls example to create a tls session without directly using sockets
#include <stdio.h>
#include <stdlib.h>
#include "mbedtls/net_sockets.h"
#include "mbedtls/ssl.h"
#include "mbedtls/error.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include <arpa/inet.h> // inet_addr
#include <stdio.h> // printf, fgets
#include <netinet/in.h> // sockaddr, sockaddr_in
@greglangford
greglangford / playbook.yml
Created January 26, 2023 13:08
Jinja2 Block to Ansible Variable
- hosts: localhost
connection: local
tasks:
- debug:
msg: '{{ __virt_install_disks }}'
vars:
__virt_install_disks: >-
{% if __x is not defined -%}
@greglangford
greglangford / raspberry-pi-bootstrap.sh
Last active September 23, 2021 23:42
raspberry-pi-bootstrap.sh
#!/bin/bash
log() {
local type="$1"; shift
printf '%s [%s] : %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
}
log_info() {
log INFO "$@"
}
- command: some command here
register: some_command_here_output
- debug:
msg: '{{ some_command_here_output }}'
# only run if needed
- command: some command here
when: some_command_here_output.stdout is search('string in the stdout of the some command here command')
function fetch(request) {
validateRequest(request);
let url = request.url;
let userAgent = request.userAgent || null;
let timeout = request.timeout || 10000;
let waitUntil = request.waitUntil || 'networkidle2';
return new Promise(function(resolve, reject) {
puppeteer.launch({executablePath: chromiumBrowserExecutable}).then(function(browser) {
@greglangford
greglangford / main.rb
Last active July 30, 2019 14:52
Ruby net http, yield response with follow redirects
require 'net/http'
urls = [
'http://www.greglangford.co.uk'
]
def request(url, method)
uri = URI(url)
response_is_not_redirect = false
@greglangford
greglangford / main.rb
Last active July 30, 2019 11:11
Ruby HTTP streaming
require 'net/http'
require 'stringio'
urls = [
'http://www.greglangford.co.uk',
'https://www.greglangford.co.uk/docker-compose-unable-to-connect-to-port/',
'https://www.greglangford.co.uk/stm8-8-bit-timer-configuration/'
]
def get_body(url)
void ICACHE_FLASH_ATTR scan_cb(void *arg, STATUS status) {
uint8 bssid[6];
uint8 ssid[33];
sint8 rssi;
uint8 best_bssid[6];
uint8 best_ssid[33];
sint8 best_rssi;
if (status == OK) {
rssi = 0;
---
- hosts: all
tasks:
- command: ls /tmp
register: files
- debug: msg="{{ item }}"
with_items: "{{ files.stdout_lines[-3:] }}"