Skip to content

Instantly share code, notes, and snippets.

@shtaxxx
shtaxxx / 60-udev.rules
Created November 9, 2012 02:29
Automatically setting ttyUSB device permissions
KERNEL=="ttyUSB*", GROUP="grpname", MODE="0666"
@shtaxxx
shtaxxx / init.el
Created November 13, 2012 09:28
My emacs init.el
;; Environment dependent settings
;;use (eq window-system `name) and (eq emacs-major-version num)
(cond
((eq window-system nil)
(load-file "~/.emacs.d/terminal.el"))
((eq window-system `ns)
(load-file "~/.emacs.d/cocoa.el"))
((eq window-system `mac)
(load-file "~/.emacs.d/carbon.el"))
((eq window-system `x)
import ast
import inspect
import sys
def create_func_from_ast(targ, arg_globals=globals()):
source = "def __target_func__(*args, **kw): return True\n"
func_ast = ast.parse(source)
func_ast.body[0].body[0].value = targ
func_ast = ast.fix_missing_locations(func_ast)
code = compile(func_ast, '<string>', 'exec')
#-------------------------------------------------------------------------------
# get an AST of a function defined in globals()
#-------------------------------------------------------------------------------
import ast
import inspect
def getFunctionAst(name):
if name not in globals():
raise NameError("name '%s' is not defined" % name)
func = globals()[name]
source = inspect.getsource(func)
@shtaxxx
shtaxxx / test_gray_code.v
Created October 18, 2013 09:11
Gray Code Encoder and Decoder
module test_gray_code;
parameter DWIDTH = 10;
function [DWIDTH-1:0] to_gray;
input [DWIDTH-1:0] in;
to_gray = in ^ (in >> 1);
endfunction
function [DWIDTH-1:0] to_binary;
@shtaxxx
shtaxxx / async_fifo.v
Created October 19, 2013 04:47
Asynchronous FIFO and its test (Verilog HDL)
module test;
parameter DATA_WIDTH = 32;
parameter ADDR_LEN = 10;
reg CLK0;
reg RST0;
wire [DATA_WIDTH-1:0] Q;
reg DEQ;
wire EMPTY;
wire ALM_EMPTY;
@shtaxxx
shtaxxx / fizzbuzz.rb
Created October 24, 2013 08:38
FizzBuzz
#1.upto(?d){|i|puts"#{i%3<1?'Fizz':i%5>0?i:''}#{'Buzz'if i%5<1}"}
#1.upto(?d){|i|puts [[:Fizz][i%3],[:Buzz][i%5]]*''}
#1.upto(?d){|i|i%3<1&&x=:Fizz;puts i%5<1?"#{x}Buzz":x||i}
#1.upto(?d){|i|puts [i%3<1?:Fizz:i%5>0?i:'',[:Buzz][i%5]]*''}
#?d.times{|i|puts [i%3<1?:Fizz:i%5>0?i:'',[:Buzz][i%5]]*''}
100.times{|i|i%3<1&&x=:Fizz;puts i%5<1?"#{x}Buzz":x||i}
@shtaxxx
shtaxxx / meiro.rb
Created October 24, 2013 08:38
A-star
#!/usr/bin/env ruby
DATA = "**************************
*S* * *
* * * * ************* *
* * * ************ *
* * *
************** ***********
* *
** ***********************
* * G *
@shtaxxx
shtaxxx / timer.rb
Created October 24, 2013 08:39
Timer using say command
#!/usr/bin/env ruby
USAGE = "$ ruby timer.rb time time ..."
if ARGV.length == 0 then
puts USAGE
exit
end
tl = []
@shtaxxx
shtaxxx / ToEuc.rb
Created October 24, 2013 08:39
Encoding converter
#!/usr/bin/env ruby
IO.popen("nkf -g *","r+"){|io|
while (l = io.gets) != nil
if /(^.*):Shift_JIS$/ =~ l then
tmp = $1
if /(.*)\.Shift_JIS$/ =~ $1 then
next
end
print "S: #{tmp}\n"