Pyhton can convert most (all) lists/collections into iterator objects, this is done by calling iter() ie
num_list = [1, 2 …Pyhton can convert most (all) lists/collections into iterator objects, this is done by calling iter() ie
num_list = [1, 2 …How to package a pythin script or project for distribution. Offical Docs are [here][python_package]. Packaging for pip requires use …
read moreIn the aim of keeping the navigation of the Blog posts clean, I have limited my self to a few …
read moreFirst figure out which theme you are using. List installed themes via:
% pelican-themes -l
simple
notmyidea
pelicanconf.py does not …
read moreI think it improves website usability when they are navigatable via the URL.
For example when viewing Posts under the …
read more^ Matches the beginning of a line
$ Matches the end of the line
. Matches any character …Creating/Setup a pyhton virtual enviroment called 'venv'
python3 -m venv venv
Load the virtual env called venv
source venv …Convolution in Python, for merging filter responses, creating pascals triangle ...
import numpy as np
a= np.array([1,1])
b …Perforce can temporarily checkins of changes that you might want to share with others before fully commiting them to the …
read moreUsing python script to merge pdfs together.
Install package
pip install pypdf
Script:
from pypdf import PdfWriter
pdfs = ['file1.pdf …On the journey towards publish static site generator blog posts from iPadOS, my next step after installing stash on pythonista …
read moreInstalling stash on pythonista
read morePython example for reading data from a csv file.
import csv
with open(data.csv', newline='') as csvfile:
spamreader = csv …Create and plot a sinewave in python
read moreerror: storage class specified for parameter
There is probably a missing semicolon ; in a header file! Just written my first …
As I use the code blocks for ingredient lists on my recipe pages I wanted to have a different style …
read moreRuby 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 …Creating new posts in Octopress is rake new_post["Edit Posts"] which outputs the created filename.
Posts are prefixed with date …
read moreBased on post_filters by imathis.
First Move the original method out the way with alias_method then create a new method …
In ruby Dir.entries takes a path and returns a list of its contents. However it does not deal with …
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 moreNormally this would just end up on my link blog, but thought it was worthy of a proper mention.
read moreConfigurable order of numbers:
x+y = y+x
xy = yx
Order that multiplication is applied :
(x+y)+z …How 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 this example we will have a data file with two columns of data labelled A and B. For example …
read moreFollowing on from Macbook Pro Setup, Now it is time to install some of the command line tools.
I have …
read moreMacBook Pro with Lion arrives, before installing any other software apply for the Up-to-Date Programme for free a mountain lion …
read moreAfter deciding to try out epub on the kindle, as I noticed people are listing epub as an apple format …
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 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 moreAre you running into the following error
Encoding::UndefinedConversionError - "\xE2" from ASCII-8BIT to UTF-8:
If you are using Ruby and …
read moreWhile working on this site I wanted to find a simple way of trying out multiple stylesheets for different colour …
read moreWorking on my site design I thought it would be nice to have user selectable stylesheets, say a black text …
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 …
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 moreWhen working with HDLs (Hardware Description Languages) there a few things that could be improved/made easier:
Renaming a file …
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 make an automatic ActiveRecord database connection using ENV['DATABASE_URL'] The following snippet can be used:
From ActiveRecord 3.2 …
read moreTo connect to a rails style DB config outside of the normal workflow, or using a database.yml in a …
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 …Classes 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 moreI have just finished some minor updates to the site. The largest is the move to Droid Fonts, Google Fonts …
read moreBased on an old Article I wrote, investigating incase sensitive sorting performance.
I have an active record model call Tag …
read moreUsing Tags (An active record model) to find tags by the tag property:
Tag.find_by_tag("Ruby")
Ruby
Tag.find_by_tag(["Ruby …After 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 moreSince moving to Classy Sinatra applications I have not been able to get put and delete methods to work correctly …
read moreI am currently switching between runing migrations locally on an sqlite3 database and postgres for production on Heroku.
When switching …
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 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 moreCSS or Cascading Style Sheets are used for styling html elements. HTML elements can have id's, which must be unique …
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 …After updating my website on webfaction nginx kept saying permission denied and when I tried to view my site I …
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 moreIf you are trying to use the 64 bit version of handbrake on Snow Leopard do not for get that …
read moreI might have just made up includable, but I like it.
Some times you have written a ruby script (using …
read moreThe '413 Request Entity Too Large' Error message is because you have filled in a form and are submitting it …
read moreDownload ruby enterprise and follow instructions on page. The exact commands I used are:
$ cd ~/bin
$ wget http://rubyforge.org …A simple Sinatra web app to upload a single file. Also available as a gist, based on http://pastie.caboo …
read moreWith Webfaction you can create new users with there own home area but there is no straight forward way to …
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 moreJust a short first note to announce the fact that the site is finally up.
We are running on WebFaction …
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