To set a default define option while allowing it to be overridden from the command line.
`ifndef mode_sel
`define mode_sel …
To set a default define option while allowing it to be overridden from the command line.
`ifndef mode_sel
`define mode_sel …
The best practice is to use a tcl file:
shm.tcl
database -open waves -shm
probe -create your_top_level -depth all …
Time can be displayed during simulation using %t
.
$display("%t", $realtime);
Timeformat is used to control the way (%t
) this …
A minimal example of constrained random to constraining a 4 bit value to 0 to 11 when randomised.
module tb …
Efficiently create a thermometer code in verilog:
localparam M = 32;
function [M-1:0] therm_code;
input [$clog2(M):0] val;
begin …
1 2 3 4 5 6 7 8 |
|
To prepend to to filenames
cd to_folder
ls | xargs -I {} mv {} addthis-{}
or target jpgs
cd to_folder
ls *.jpg | xargs …
I just discovered the xkill
command, when a window has crashed you
can call xkill and get a skull and …
Setting an alias in you .tcshrc
alias qrun 'qrsh -V -noshell -cwd !*'
or bash
alias qrun='qrsh -V -noshell -cwd …
Matlab always use to open text files in tabs in the same editor window. When switching to 2014a documents started …
read moreTo set each constant in a model to sample time -1:
blks = find_system(dut, 'BlockType', 'Constant');
for i = 1:length …
Select a block ie gain in Simulink then in Matlab type:
get(gcbh)
This shows the list of properties which …
read morefind_system('BlockType', 'Gain')
This will list all gain blocks in currently loaded models. to limit to a particulat model:
find_system …
error: storage class specified for parameter
There is probably a missing semicolon ;
in a header file! Just written my first …
To redirect stdout and stderr in bash we use:
./ShellFile.sh &> test.log
However in tcsh that results in:
Invalid …
As I use the code blocks for ingredient lists on my recipe pages I wanted to have a different style …
read moreTo wait for a maximum of 10ns
for positive edge on clk then carry on with simulation.
fork : wait_or_timeout
begin …
To add X and Y grids to plots :
grid on;
To add Y only grid:
set(gca,'XGrid','off','YGrid …
Wrap strings with sprintf
to allow the \n
to be escaped correctly.
>> disp('hello\nworld')
hello\nworld
>> disp(sprintf('hello …
When a script or function is called with run(./relative/path/script)
the working directory is changed to the ./relative …
Checking if an Array contains a number:
input = [1,2,3,4];
check = 4;
any(input==4)
Check if a …
read moreUsing Matlab to splitting data into odd and even samples.
A for loop approach:
data_odd = [];
data_even = [];
for i = 1:length …
Ruby methods can set default values for optional arguments:
def commit(path=Dir.pwd)
To take an optional number of …
read moreWith a command line Ruby application using Thor for the option parsing I want to be able to run:
$ thor_app …
Lightroom plugins for metadata views are called metadata tag sets and only require 2 text files.
create a folder called …
read moreBased on a Stackoverflow answer, to import environment variables into Verilog you can use:
import "DPI-C" function string getenv(input …
For adding leading zeros to a number the following can be used for 4 decimal places with integer input:
dat …
To wrap a function with variable input arguments and pass them all on to the wrapped function. Based on a …
read moreHandling functions with extraneous leading outputs. For example:
function [a,b] = dummy_function
a = 10;
b = 20;
endfunction
[a, b] = dummy_function …
In Verilog to output to stdout without a line return use $write();
Equivalent statements :
$write("\n");
$display("");
rtorrent moving torrents upon completion:
# Torrents go in ~/Torrents
# Incomplete Downloads in ~/Incomplete
# Upon Completion Data is moved to ~/Seeding …
Good programming practice is to use spaces to indent code rather than tabs. Due to tabs often being rendered differently …
read moresetenv allows sub shells to inherit the value.
set x = "twenty"
echo $x
> twenty
## New Shell
csh
echo $x …
A typical work flow in Matlab involves a folder filled with scripts and functions. Over time this folder grows until …
read moreTo check if an environment variable exists in .mycshrc or shell scripts
if ($?TERM) then
echo "TERM is $TERM"
endif …
In ruby Dir.entries takes a path and returns a list of its contents. However it does not deal with …
read moreI have decided to clean up my vim colorschemes. I have been using ir_black for sometime but it does not …
read moreI was wanting to use Dir.glob to get a file list and wanted to do Dir.glob( path + '*')
but …
To add static about page to octopress blog, assuming that octopress has been already setup:
Create the page from the …
read moreAfter struggling to get the rake task for octopress to deploy I decided to fall back to the command line …
read moreNormally this would just end up on my link blog, but thought it was worthy of a proper mention.
read moreHow to get method which handles a single string input or an array of strings?
* turns single strings into …
read moreTake an array of arrays and format it for displaying to the terminal or outputting to a text file …
read moreGiven a flat hierarchy of data comprising level and a label, aim to nest the lower level of objects in …
read moreFor code reuse within I have found Subversion externals really nice to work with. Instead of copy and pasting code …
read moreTo reduce an array of Booleans to a single Boolean using enumerables reduce method:
[true, true, true].reduce( :| ) ## OR
=> true …
In ruby you can catch StandardErrors using begin rescue end
begin
#Some thing which might fails
rescue
$stderr.puts $!
end …
There was an interesting post on hacker news recently, safeshepherd suddenly fell off the google for their own name. The …
read moreWhen working behind a restrictive firewall, which limits ssh connections you may be running into some of the following errors …
read moreAfter making a few updates to my site it stopped working after deploying. The issue was that the gem version …
read moreThere are gzip compression options available but when I looked at this a long time ago I found that the …
read moreI have been setting up my recent Sinatra projects with a standard ruby project layout putting all of the application …
read moreUpdate RVM
$ rvm get head
List current versions, and all versions
$ rvm list
$ rvm list known
Select the version you …
read moreSometime a script needs to now the directory that it is executing from, the best solution for this is:
DIR …
Are you running into the following error
Encoding::UndefinedConversionError - "\xE2" from ASCII-8BIT to UTF-8:
If you are using Ruby and …
read moreWorking on my site design I thought it would be nice to have user selectable stylesheets, say a black text …
read moreA simple script for finding temp files from the current directory and below. I often run this before adding a …
read moreOriginally written as an assignment for Ruby Mendicant University.
matrix is part of the Ruby Standard Library
A note …
read moreThere does not appear to be a nice way to get a current users real name in ruby. The best …
read moreSuppressing warnings is usually a bad idea but if you understand the risk and want to carry on regardless. When …
read moreThere is a very good presentation Confident Code by Avdi Grimm author of http://exceptionalruby.com/. Previously presented at Cascadia …
read moreBack in 2009 barkingiguana wrote about how explicit returns 'return "String"'
was slower than an implicit return, ie just letting …
This assumes that origin
is the label for github.
Tagging a github repo for my gem releases I do:
$ git …
Previous posts arrays and arrays2
Based on a post by barkingiguana, some idiomatic ruby ways to handle arrays. Ruby tries …
read moreA small standalone script that search through a file doing text substitutions.
1 2 3 4 5 6 7 8 … |
Do you some times see:
FileUtils.rb:93: warning: already initialized constant OPT_TABLE
FileUtils.rb:1176: warning: already initialized constant …
Building on my original Ruby Arrays article a few more things you can do with Ruby Arrays.
Concatenation
a = [1 …
While working on some disk space / folder structure scripts I had several functions which hierarchically search the disk then performed …
read moreRead text file with one line:
Write text with one line :
When reading a text file …
read moreWorking on a joint project an error started showing up when trying to perform migrations.
$ rake db:migrate VERSION=0 …
To connect to a rails style DB config outside of the normal workflow, or using a database.yml in a …
read moreThis vim plugin will allow you to gist directly from vim, simple way is just :Gist to gist entire file …
read morerecenlty after updating rubygems Istarted getting a lot of warning like this when running ruby or executable gems:
NOTE: Gem …
read moreWhen running gem build on a new library I have been working on I started getting the following error:
[ruby_svg_light …
I have not fully read it but it looks like this is a good guide to bash scripting. A few …
read moreIn Vim to insert text before the cursor press 'i', to insert text after cursor 'a' or to edit at …
read moreClasses are a basic Object Orientated Structure which encapsulate state and behaviour. Some times you just require to capture state …
read moreBased on 'Raise the bar, lower the pressure' given by Durran Jordan at ScotRubyConf 2011.
There has been some debate …
read moreI recently heard about the Schwartzian transform, which is a sorting idiom from perl. It allows an array of objects …
read moreUsing a while true loop with 'gets' and a case statement, can create a compact command line interface for ruby …
read moreBased on an old Article I wrote, investigating incase sensitive sorting performance.
I have an active record model call Tag …
read moreAfter making a few updates to my site I decided to upgrade the version of sinatra I was using in …
read moreThe routes for my site have been growing since adding pagination (/articles/older/) and tag filtering. As well as the …
read moreA new very cool plugin for Rubyists using Vim. RubyBlock TextObjects created by Drew Neil from Vimcasts.org. Once installed …
read moreI think it is good practise to create a read only tag when releasing an application. This allows you to …
read moreRack applications often require a config.ru for deployment. The standard config.ru for classic sinatra applications is well documented …
read moreI have just started to use a sinatra extensions called Sinatra Session. The write up on the main site is …
read moreSinatra Reloader is a sinatra extension which reloads source files while in development mode, this functionality was removed from base …
read moreIn ruby some times you want to iterate over an array and remove items that meet certain conditions, if using …
read moreI have for a while wondered about an ideal (good) approach to storing api keys in config files in ruby …
read moreThe new EC2-Pricing also includes a new Micro service. This micro service is intended for small apps servicing tens of …
read moreI recently discovered a feature of regular expressions called lookahead. This means for a match the lookahead must exist but …
read moreOne method to save a time and restore it correctly:
def get_time_run
## File Access based on
## http://rubylearning.com/satishtalim …
When running a sequel migration I kept getting this error:
Error: NoMethodError: undefined method `compact' for nil:NilClass
My setup …
read moreIn Active Record when updating records I used to have an very manual process to this some thing like:
@todo …
When working with databases it is often a requirement to have unique elements (columns) which are not the primary key …
read moreAn example of joining tables through active record models. There is a good tutorial on the basics of Activerecord joins …
read moreI have been wondering how to do this for a while and accidentally discovered it while perusing this heroku page …
read moreFollowing this article lets you turn a executable java .jar into a mac appliction (.app). The Tools are only available …
read moreI have been trying to use the GeoIP Rack App, by copying this gist in my Rack stack with a …
read moreI used this as a jQuery reference to hide and show default text in forms.
<head>
<script type=”text/javascript …
This snippet can be added to you ~/.vimrc to highlight long lines.
" Highlight lines over 80 characters long with red …
To search in Vim just press (apple-f for macvim) / then search string.
/search
This will highlight all occurrences of 'search' …
read moreThis is not necessarily the correct way of creating executable gems but a method which worked for me.
Assuming we …
read moreJust released my first gem 'memory_usage' Version 0.0.1.
$ gem install memory_usage
Assuming the gems folder has been set-up …
read moreI might have just made up includable, but I like it.
Some times you have written a ruby script (using …
read moreI have written a few command line tools in ruby which I use to perform file system maintenance. Mainly sorting …
read moreBy default git status returned differences in file permissions. To turn if off run:
$ git config core.filemode false
A simple Sinatra web app to upload a single file. Also available as a gist, based on http://pastie.caboo …
read moreThis feature of ruby keeps catching me out as the behaviour is quite unexpected (by me).
I can use a …
read moreRuby has a .sort method which sorts basic objects. it is case sensitive though so Zebra is before apple. Using …
read moreI have just forked and cloned a project on github and discovered *.gemspec files. They are a nice way of …
read moreI recently discovered ||= in ruby. Its main use is for initialising a variable if it does not already exists, this …
read more[Update]
As this is a long post I am putting this update at the top. If you just want to …
When I install gems on my server I do not get any of the documentation which is normally 3-5 times …
read moreWhen displaying blog/articles it is often nice to have previous and next posts. Simply -1 +1 from the current …
read moreSinatra 1.0 has been released!
When you install the new version the old one are still left behind. This …
read moreGit has a hand full of GUIs available on Mac OS X, gitk proved a little tricky to use but …
read moreI have been playing around with getting my blog posts timestamped I found the Ruby Time Docs to be very …
read more