Skip to content

Instantly share code, notes, and snippets.

View viewpointsa's full-sized avatar

viewpointsa

  • ViewPoint
  • Lyon - France
View GitHub Profile
find . -type f | egrep '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{8}' | xargs rm
s = "0e59f1d5-1fbe-11d0-8ff2-00a0d10038bc"
#DEFINE_GUID(IID_IScriptControl, 0x8b167d60, 0x8605, 0x11d0,
# 0xab, 0xcb, 0x00, 0xa0, 0xc9, 0x0f, 0xff, 0xc0);
#"0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s" % ( s[0:8], s[9:13], s[14:18], s[19:21]
arr = [8,4,4,2,2,2,2,2,2,2,2]
print "DEFINE_GUID(IID_IXXX," + ','.join( map( lambda kv: '0x' + s.replace('-','')[ sum(arr[:kv[0]]) : sum(arr[:kv[0]]) + kv[1] ], enumerate(arr) ) ) + ");"
#/bin/bash
if [ $# -ne 2 ]; then
echo $0: usage: myscript databasename zipfile
exit 1
fi
dbname=$1
psql --command "select pg_terminate_backend(procpid) from pg_stat_activity where datname = '$dbname';"
@viewpointsa
viewpointsa / xslt.py
Created March 1, 2019 09:45
python XSLT processing XML
import lxml.etree as ET
import argparse
parser = argparse.ArgumentParser(description='XSLT Transform XML file.')
parser.add_argument('xml', help='input xml file')
parser.add_argument('xsl', help='input xslt file')
parser.add_argument('-o', '--output', help='Output file')
args = parser.parse_args()
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Validation CalcDiffMean"
]
},
{
@viewpointsa
viewpointsa / ArduinoMkrfox1200RTC3231.uno
Created April 16, 2019 12:38
Dialog Arduino Mkrfox 1200 with RTC3231
/*
^ DS3231 ^Arduino ^
| SCL | 12 SCL |
| SDA | 11 SDA |
| VCC | VCC |
| GND | GND |
*/
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
@viewpointsa
viewpointsa / bd_copy_table.py
Created February 27, 2019 10:37
Copy table from postgresql database to another
import psycopg2
import argparse
def copy_table( connectionStringSrc, connectionStringDst, table_name, verbose=False, condition="" ):
with psycopg2.connect(connectionStringSrc) as connSrc:
with psycopg2.connect(connectionStringDst) as connDst:
query = "SELECT * FROM {} {};".format(table_name,condition)
with connSrc.cursor() as curSrc:
curSrc.execute( query )
print "Source number of rows =", curSrc.rowcount
import struct, time, zlib
def generate_gzip():
# Migration Python2 to 3 https://stackoverflow.com/a/44387566/2137364
# Yield a gzip file header first.
yield (
b'\037\213\010\000' + # Gzip file, deflate, no filename
struct.pack('<L', int(time.time())) + # compression start time
b'\002\377' # maximum compression, no OS specified
)
import paho.mqtt.client as mqtt
import sys
import json
from random import random
import ssl
import os
# This is the Publisher
data = json.dumps({
'temperature' : random() * 20.0,