Skip to content

Instantly share code, notes, and snippets.

View mvidner's full-sized avatar

Martin Vidner mvidner

  • SUSE
  • Prague, CZ, EU
View GitHub Profile
@mvidner
mvidner / fly.sh
Created March 24, 2017 14:23
A USB controlled fly
(sleep 5; echo 1700; sleep 2; echo 1500; sleep 1.1; echo 0) | socat - /dev/ttyUSB0,b115200,rawer
# encoding: utf-8
module Yast
class ReplacePoint1Client < Client
def main
Yast.import "UI"
UI.OpenDialog(
VBox(
ReplacePoint(Id("rp"), Label("This is a label with a string Id")),
PushButton(Id(:change), "Change")
#!/usr/bin/env python2
# Send a BEEP command via USB to a Lego Mindstorms EV3 brick
import sys
import usb.core # https://walac.github.io/pyusb/
def ev3_write(command):
# To send commands, we need an Endpoint.
/*
* Copyright (c) 2014 Angelo Naselli <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:

Vega is the second brightest star in the northern celestial hemisphere. Its name comes from the Arabic name "wāqi‘" (an-nasr al-wāqi‘), meaning "falling" (falling eagle). In the Arabic script, it is واقع (النسر الواقع).

Note how the parenthesized phrase ends up in the middle of the sentence, even though it should go at the end like this:

In the Arabic script, it is WAQE (ALNASR ALWAQE).

(Must include screenshots, because all renderers have their own incompatible sets of bugs)

#!/usr/bin/ruby
# coding: utf-8
def char_as_4hex(c)
format("%04x", c.ord)
end
REPLACEMENT = "\ufffd" # �
FSI = "\u2068" # First Strong Isolate
PDI = "\u2069" # Pop Directional Isolate
#!/usr/bin/ruby
require "fileutils"
require "pathname"
include FileUtils
FILTER_OUT_RES = [
"warning: PO file header fuzzy",
"warning: older versions of msgfmt will give an error on this",
# a dead stupid profiler/debugger
# usage: ruby -r .../trace_func_profiler.rb my_program.rb
set_trace_func proc { |event, file, line, id, binding, classname|
unless ["line"].include? event
m = "#{classname}.#{id}"
t = Time.now.strftime("%H:%M:%S.%4N")
printf "%s|%8s %s:%-2d %s\n", t, event, file, line, m
end
}
@mvidner
mvidner / command-quiz-all-in-one.rb
Last active May 31, 2017 07:42
What do these files do when you run them with Ruby?
#!/usr/bin/ruby
# Ruby Gotcha Quiz, by Martin Vidner
# Aimed at people who have written something in Ruby already
def command(s)
system(s)
end
command "echo A"
@mvidner
mvidner / RUNME.sh
Last active June 20, 2016 14:11
ruby-lint loading definitions of overlapping namespaces
#!/bin/sh
ruby app.rb
ruby-lint -c cfg-top.yml app.rb
ruby-lint -c cfg-nested.yml app.rb
exit
# the definitions were made like this
rake -r project-base generate:definitions[Project,.]; mv project.rb defs-project.rb
rake -r project-ui generate:definitions[Project,.]; mv project.rb defs-ui-top.rb
rake -r project-ui generate:definitions[Project::UI,.]; mv project.rb defs-ui-nested.rb