Skip to content

Instantly share code, notes, and snippets.

@ericsalim
ericsalim / xmerl_xml_indent.ex
Created December 12, 2021 09:46
Indent XML using Elixir
# Module declaration
defmodule :xmerl_xml_indent do
@moduledoc """
Erlang OTP's built-in xmerl library lacks functionality to print XML with indent.
To work around this, we must create a custom callback to indent XML.
This callback is taken from https://github.com/erlang/otp/blob/master/lib/xmerl/src/xmerl_xml.erl
The code is converted to Elixir and modified for indentation.
This callback works only if the original XML string is a one-liner without identation.
"""
##### start of rpicenter library code #####
from abc import ABCMeta, abstractmethod
from threading import Thread
class Adapter():
def __init__(self, device_object_id, slot, gpio_pin):
self._device_object_id = device_object_id
self._slot = slot
self._gpio_pin = gpio_pin
### what this script does:
### 1. get the ip of the machine, check whether hdmi is plugged
### 2. send the ip by email
### 3. repeat step 1 and 2 several times
### 4. if step 3 ok, quit
### 5. if step 3 not ok, in X second check flag file auto_shutdown_1 exists
### 6. if flag file exists, shutdown
## user config ##
@ericsalim
ericsalim / select100k_psycopg2.py
Created May 22, 2016 04:43
Select 100k rows using Psycopg2
import psycopg2
import psycopg2.extras
import sys
import time
conn = None
class Generic:
pass
@ericsalim
ericsalim / select100k_sqla.py
Created May 22, 2016 04:41
Select 100k rows using SQLAlchemy
from sqlalchemy import create_engine
import sys
import time
conn = None
class Generic:
pass
try:
@ericsalim
ericsalim / insert100k.py
Last active May 22, 2016 04:56
Inserting 100k rows
from sqlalchemy import create_engine
conn = None
try:
conn_str = "postgresql+psycopg2://postgres:password@localhost:5432/test"
engine = create_engine(conn_str, pool_size=3)
conn = engine.connect()
for i in range(0, 100000):
sql = "insert into table1 (a,b,c,d,e) values (%s,%s,%s,%s,%s)"
conn.execute(sql, (i, 'string for ' + str(i), 'string for ' + str(i), i*0.1, i*0.1))
finally:
@ericsalim
ericsalim / util_gen_insert
Last active August 29, 2015 14:07
Code Snippets
set quoted_identifier off
set nocount on
go
alter proc util_gen_insert
@tbl_name varchar(100)
, @where_clause varchar(max)
as
begin