(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
# Updated for Ruby 2.3 | |
string_t = None | |
def get_rstring(addr): | |
s = addr.cast(string_t.pointer()) | |
if s['basic']['flags'] & (1 << 13): | |
return s['as']['heap']['ptr'].string() | |
else: | |
return s['as']['ary'].string() |
This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.
The script is here:
#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"
I recently started a new project using rspec's newer (and soon to be default) expect
syntax, and encountered this error:
expect(5).to == 5
ArgumentError: The expect syntax does not support operator matchers, so you must pass a matcher to `#to`
"Why'd they take out operator matches? I've grown quite accustomed to them!", I thought. Digging around, the source of this change started in pull request 119 citing issue 138 as one of the root causes. Here's what's actually happening:
// LPD8806 LED Code for our Yacht Club's Anchor | |
/*************************************************************************************/ | |
#include "LPD8806.h" // Library Here: https://github.com/adafruit/LPD8806 | |
#include "SPI.h" | |
int totalLEDs = 14; | |
int dataPin = 2; | |
int clockPin = 3; | |
LPD8806 strip = LPD8806(totalLEDs, dataPin, clockPin); |
# MAC manipulators | |
alias random_mac='sudo ifconfig en0 ether `openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//"`' | |
alias restore_mac='sudo ifconfig en0 ether YOUR_ORIGINAL_MAC_ADDRESS_GOES_HERE' |
In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.
A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval
.
You can find instance_eval
used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.
class Article < ActiveRecord::Base
--type-add=css=.sass,.less,.scss | |
--type-add=ruby=.rake,.rsel,.builder,.thor | |
--type-add=html=.haml,.html.erb,.html.haml | |
--type-add=js=.js.erb,.coffee | |
--type-set=cucumber=.feature | |
--type-set=c=.c,.cpp,.ino,.pde,.h | |
--ignore-dir=vendor | |
--ignore-dir=log | |
--ignore-dir=tmp | |
--ignore-dir=doc |
require 'monitor' | |
class Semaphore | |
def initialize(maxval = nil) | |
maxval = maxval.to_i unless maxval.nil? | |
raise ArgumentError.new("Semaphores must use a positive maximum value or have no maximum!") if maxval and maxval <= 0 | |
@max = maxval || -1 | |
@count = 0 | |
@mon = Monitor.new | |
@dwait = @mon.new_cond | |
@uwait = @mon.new_cond |