Category: Programming
WordPress: Display One Post Per Category
WordPress: pre_get_posts filter to display one post per category. Displays the latest sticky post and therefore excludes the category of the sticky post as we only want one post per category.
By: Silvan Hagen
More
How To Work With LaTeX Files in Sublime Text
1. Install Package Control for Sublime Text 3 (or 2 for Sublime Text 2)
2. Using Package Control, Install LaTeXTools plugin for Sublime Text
3. Using Package Control, Install LaTeXing 3 (or 2 for Sublime Text 2) plugin for Sublime Text
4. Read the documentation for LaTeXing
How To Install Package Control on Sublime Text 3
cd "Library/Application Support/Sublime Text 3/Packages" git clone https://github.com/wbond/sublime_package_control.git "Package Control" cd "Package Control" git checkout python3Source: wbond.net
R: Saving a Multiple-Column Boxplot into PDF
n_audio = length(levels(tlx$audio)) par(mfrow = c(1,n_audio)) for (i in levels(tlx$audio)) { boxplot(tlx_overall~guidance, outline=FALSE, data=subset(tlx,audio==i), main = "All Data", xlab = i, ylab="TLX (Overall)", cex =1, cex.lab = 1, cex.main=1, cex.axis=1, pch = 23, col = 3, lwd=.5) } dev.copy2pdf(device = quartz, file = "tlx_per_audio_x_guidance.pdf") dev.off ();
Recommended Text Editors (For Mac)
Sublime Text
Pros:
Sleek interface
Great colour themes
Autocompletion
Goto anything
Multiple selection
Split editing
Cross platform
Trial
Cons:
Expensive
TextWrangler Pros: Free Customizable colour themes Find/replace regular expressions Cons: Weird window management Hard to customize colour themes
Nuggit Cheap
BBEdit Pros: Customizable colour themes Find/replace regular expressions Cons: Not too cheap
TextWrangler Pros: Free Customizable colour themes Find/replace regular expressions Cons: Weird window management Hard to customize colour themes
Nuggit Cheap
BBEdit Pros: Customizable colour themes Find/replace regular expressions Cons: Not too cheap
Ruby Kernel: caller
caller(start=1, length=nil)
→ array or nilReturns the current execution stack—an array containing strings in the form file:line or file:line: in `method'. The optional start parameter determines the number of initial stack entries to omit from the top of the stack. A second optional length parameter can be used to limit how many entries are returned from the stack. Returns nil if start is greater than the size of current execution stack. Optionally you can pass a range, which will return an array containing the entries within the specified range. [ruby-doc.org]
def a(skip) caller(skip) end def b(skip) a(skip) end def c(skip) b(skip) end c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `<main>'"] c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `<main>'"] c(2) #=> ["prog:8:in `c'", "prog:12:in `<main>'"] c(3) #=> ["prog:13:in `<main>'"] c(4) #=> [] c(5) #=> nil
DataMapper Important Rules
belongs_to :post # defaults to :required => truebelongs_to relationships will be required by default (the parent resource must exist in order for the child to be valid). You can make the parent resource optional by passing :required => false as an option to belongs_to.
Ruby – Convert Object to Hash
What's the best way to convert an Object to Hash in Ruby?
class Gift def initialize @name = "book" @price = 15.95 end end gift = Gift.new hash = {} gift.instance_variables.each {|var| hash[var.to_s.delete("@")] = gift.instance_variable_get(var) } p hash # => {"name"=>"book", "price"=>15.95}Source: Stackoverflow
DataMapper – Quick Reference
How would one specify the the combination of two fields must be unique? For example categories must have unique names within a domain:
class Category include DataMapper::Resource property :name, String, :unique_index => :u property :domain_id, Integer, :unique_index => :u belongs_to :domain endSource: stackoverflow.com
Useful Ruby Regular Expressions
Floating Point Numbers
/[-+]?[0-9]*\.?[0-9]+/