Skip to content

Instantly share code, notes, and snippets.

View denisdefreyne's full-sized avatar

Denis Defreyne denisdefreyne

View GitHub Profile
Checking sizeof(short): 2 bytes
Checking sizeof(int): 4 bytes
Checking sizeof(void*): 8 bytes
Checking sizeof(size_t): 8 bytes
Checking sizeof(long): 8 bytes
Checking sizeof(long long): 8 bytes
Checking sizeof(float): 4 bytes
Checking sizeof(double): 8 bytes
Checking sizeof(off_t): 8 bytes
Checking sizeof(time_t): 8 bytes

Why File.read in nanoc is bad and what to do about it

Abstract

In nanoc, using File.read directly is a bad idea, because it bypasses the dependency tracking and causes site recompilation to yield erroneous results.

Context

@denisdefreyne
denisdefreyne / explicit-variable-naming.md
Created September 11, 2013 17:53
Explicit variable naming

Explicit variable naming

Which one of the following do you prefer?

  • urn_for_user_id(user_id)
  • urn_for_user_id(id)
  • urn_for(user_id)
  • urn_for(id)

Lock-step versioning of two repositories/gems

Situation sketch

Imagine having three repositories:

  • nanoc-core
  • nanoc-cli
@denisdefreyne
denisdefreyne / outdatedness_checking_ng.rb
Last active December 24, 2015 05:39
Pseudocode for a new outdatedness checking approach. The goal is to have an amount of data that is linear to the number of changes, rather than the number of files.
# encoding: utf-8
module Nanoc
#############################################################################
class ItemChange
attr_reader :identifier
@denisdefreyne
denisdefreyne / subset.rb
Last active December 24, 2015 05:39
Experimental implementation of special subsets with + operator.
require 'set'
class FullSubset
def +(other)
self
end
def inspect
"<FullSubset>"
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{GentiumBasic}
\setsansfont{ITC Franklin Gothic LT Medium}
\setmonofont{Consolas}
%%%%%%%%%%
\clubpenalty=10000
\widowpenalty=10000
func pointsAtDistance(a, b, c s5t.Point, d float64) (s5t.Point, s5t.Point) {
// Slope of A-B
slope := (b.Y - a.Y) / (b.X - a.X)
// Slope of line perpendicular to A-B
perpSlope := -1 / slope
// X components of intersection of circle with radius d with line perpendicular to A-B through C
xd := d / math.Sqrt(1+math.Pow(perpSlope, 2.0))
newX1 := c.X + xd
# encoding: utf-8
class FilesystemWithRelocatedContent < Nanoc::DataSources::FilesystemUnified
identifier :filesystem_with_relocated_content
def items
load_objects('../content', 'item', Nanoc::Item)
end