Skip to content

Instantly share code, notes, and snippets.

View phearnot's full-sized avatar

Sergey Nazarov phearnot

  • Moscow, Russia
View GitHub Profile
public class Sample {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
implicit val bdStringView = StringView.of[BigDecimal] as { _.toString }
def makeStringValue[T](implicit sv: StringView) = new StringValue {
def getString(value: AnyRef) = sv(value.asInstanceOf[T])
}
bdStringValue = makeStringValue[BigDecimal]
strStringValue = makeStringValue[String]
qtyStringValue = makeStringValue[Long](StringView.of[Long] as { _.toString }
@phearnot
phearnot / buttons.html
Created April 17, 2013 13:49
A bug in either webkit or bootstrap
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Button Test</title>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<style>
#job-list {
-webkit-column-width: 23em;
[pretty]
ol = %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset
[alias]
pp = pull -p
st = status --short --branch --untracked-files
ci = commit -S
br = branch
co = checkout
df = diff
@phearnot
phearnot / sainsmart-relay-control.py
Created June 12, 2019 15:02
SainSmart 5V USB Relay Module control script
from pyftdi.ftdi import Ftdi
from sys import argv
from array import array
import re
if re.fullmatch(r'[\.x]{4}', argv[1]):
relay_mask = sum([flag == 'x' and value or 0 for flag, value in zip(argv[1], [1, 2, 4, 8])])
ftdi = Ftdi.create_from_url('ftdi:///1')
ftdi.set_baudrate(9600)
from datetime import datetime
import fileinput, re
MESSAGE_REGEX = re.compile(r'(^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}) .+ - ((New height|Imported|Opening import).+)$')
first_ts = 0
def process(line):
global first_ts
result = MESSAGE_REGEX.match(line)