Skip to content

Instantly share code, notes, and snippets.

View norman's full-sized avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
function eval_data(string)
local chunk, err = loadstring(string)
if not chunk then error(err) end
local result = {}
setfenv(chunk, result)
chunk()
return result
end
class MyUniqifier
include Snowflake::Base
# "Strategies" are method definitions that start with "try" and will be
# tried in the order you create them in your uniqifier class.
def try_using_name
@record.name
end
@norman
norman / gist:2845232
Created May 31, 2012 18:23
Haml Benchmarks
These benchmarks process a template that uses most of Haml's features.
(1) Parsed, compiled and rendered
(2) Compiled and rendered
(3) Rendered
Stable branch:
user system total real
ugly (1) 1.120000 0.010000 1.130000 ( 1.132223)
@norman
norman / git-log-deletions.sh
Created May 30, 2012 16:05
Git trick to show additions and deletions between branches
git log stable..rails3 --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s\n",add,subs,loc }' -
added lines: 13821 removed lines: 16327 total lines: -2506
require "babosa"
require "babosa/utf8/proxy"
bad_string = "whatever"
puts Babosa::UTF8::DumbProxy.tidy_bytes bad_string
<p>
foo
</p>
<textarea>
hello world</textarea>
<p>
hello world
</p>
<textarea>hello!</textarea>
# coding: utf-8
#
# Copyright (c) 2012 Norman Clarke
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
@norman
norman / character_reference.rb
Last active September 9, 2021 20:48
HTML entities? We don't need no stinkin' HTML entities.
# coding: utf-8
#
# Encode any codepoint outside the ASCII printable range to an HTML character
# reference (https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_reference_overview).
def encode(string)
string.each_codepoint.inject("") do |buffer, cp|
cp = "&#x#{cp.to_s(16)};" unless cp >= 0x20 && cp <= 0x7E
buffer << cp
end
end
user system total real
(1) erb 0.360000 0.000000 0.360000 ( 0.355804)
(1) erubis 0.300000 0.000000 0.300000 ( 0.305106)
(1) fast erubis 0.300000 0.000000 0.300000 ( 0.304546)
(1) slim 3.030000 0.010000 3.040000 ( 3.036167)
(1) haml 1.990000 0.010000 2.000000 ( 2.012734)
(1) haml ugly 1.870000 0.000000 1.870000 ( 1.873722)
(2) erb 0.130000 0.000000 0.130000 ( 0.126759)
(2) erubis 0.090000 0.000000 0.090000 ( 0.094110)
@norman
norman / compat_env.lua
Created March 30, 2012 21:06 — forked from davidm/moved.md
Lua module 'compat_env' - Lua 5.1/5.2 environment compatibility functions
--[[
compat_env v$(_VERSION) - Lua 5.1/5.2 environment compatibility functions
SYNOPSIS
-- Get load/loadfile compatibility functions only if using 5.1.
local CL = pcall(load, '') and _G or require 'compat_env'
local load = CL.load
local loadfile = CL.loadfile