Skip to content

Instantly share code, notes, and snippets.

function fixhtml(html) {
var div, dom, hasBlockChild, needWrapping, textOrInlineChildren, treeWalker;
dom = document.createElement('div');
html = html.replace(/\s+/g, " ").replace(/> </g, "><"); // removes white space
while (html.match(/<(h[1-5]|p|strong|div|u|em|a|bi) ?[^>]*>\s?<\/\1>/g)) {
html = html.replace(/<(h[1-5]|p|strong|div|u|em|a|b|i) ?[^>]*>\s?<\/\1>/g, ""); //removes empty tags recursively, except iframes
}
dom.innerHTML = html;
Array.from(dom.querySelectorAll("h1 h1")).forEach(function(node) {
return node.outerHTML = node.innerHTML; //unwrap nested h1's
execve("/app/.heroku/node/bin/node", ["node", "script.js"], [/* 39 vars */]) = 0
brk(0) = 0x417b000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa01618000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=43013, ...}) = 0
mmap(NULL, 43013, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffa0160d000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
2017-06-27T08:17:13.468857074Z app[web.1]: Invalid memory access (signal 11) at address 0x0
2017-06-27T08:17:13.470053308Z app[web.1]: [0x6363d5] *CallStack::print_backtrace:Int32 +117
2017-06-27T08:17:13.470384157Z app[web.1]: [0x5f2ecd] __crystal_sigfault_handler +61
2017-06-27T08:17:13.471176757Z app[web.1]: [0xd2d9b4] sigfault_handler +40
2017-06-27T08:17:13.471234670Z app[web.1]: [0x7f44602c3340] ???
2017-06-27T08:17:13.471644884Z app[web.1]: [0x7f4460bd5dd9] ???
2017-06-27T08:17:13.471718207Z app[web.1]: [0x7f4460bd6a63] ???
2017-06-27T08:17:13.472143543Z app[web.1]: [0x7f4460bd6bc9] ???
2017-06-27T08:17:13.472553163Z app[web.1]: [0x7f4460bd8931] ???
2017-06-27T08:17:13.472859127Z app[web.1]: [0xa98316] *OpenSSL::SSL::Socket::Client#initialize<TCPSocket, OpenSSL::SSL::Context::Client, Bool, String>:Nil +182
@crisward
crisward / crystaldb-0.21.0-dump
Created February 22, 2017 11:12
crystaldb-0.21.0-dump
Error in src/app/database/database.cr:11: instantiating 'DB:Module#open(String)'
@@db : DB::Database = DB.open(DBURL + "?max_pool_size=10&initial_pool_size=2&max_idle_pool_size=2")
^~~~
in lib/db/src/db.cr:103: instantiating 'build_database(String)'
build_database(uri)
^~~~~~~~~~~~~~
@crisward
crisward / mess.cr
Created December 10, 2016 21:47
crystal passing class method as a callback
class Do
def that
x = 10
while x > 0
yield x
x-=1
end
end
end

The line of code causing this looks like this. Publish and button are int8

      res = @db.exec("
        Update pages set
        title = ?, parent_id = ?, template = ?, publish = ?, button = ?,`order` = ?,
        meta = ?, created_at = ?, updated_at = ?
        where id = ?
      ", title, parent_id, template, publish, button, order, meta, created_at, updated_at, id)
@crisward
crisward / test.cr
Created November 24, 2016 09:33
testing crystal
Module App
Class UserService
initialize(@orgService : OrgService)
end
def get(id)
db.sql("select * from users where id = ?")
#....
user.org = @orgService.get(user.org_id)
@crisward
crisward / db-result.cr
Last active September 25, 2016 20:16
Select fields
struct Org
DB.mapping({
id: Int32,
name: {type: String, nilable: true},
address: {type: String, nilable: true},
postcode: {type: String, nilable: true},
created_at: {type: Time, nilable: true},
updated_at: {type: Time, nilable: true},
deleted_at: {type: Time, nilable: true},
@crisward
crisward / crystal-exception.log
Created August 27, 2016 17:27
crystal db exception
Exception: end of file reached (IO::EOFError)
[4340973938] *CallStack::unwind:Array(Pointer(Void)) +82
[4340973841] *CallStack#initialize:Array(Pointer(Void)) +17
[4340973800] *CallStack::new:CallStack +40
[4340944489] *raise<Exception+>:NoReturn +25
[4341592831] *DB::Database@DB::QueryMethods#query<String, String>:MySql::ResultSet +143
[4341685147] *Pages#from_path<String>:(Page | Nil) +43
[4341636559] *Pages#render_path<HTTP::Server::Context>:(Int32 | String | Nil) +287
[4340948641] ~procProc(HTTP::Server::Context, (Int32 | String | Nil))@./src/crystal2.cr:26 +33
[4340947973] ~proc3Proc(HTTP::Server::Context, String)@./libs/kemal/kemal/route.cr:11 +101
@crisward
crisward / mess.cr
Last active October 21, 2016 13:54
kemal mysql
require "./mess/*"
require "kemal"
require "json"
require "mysql"
require "pool/connection"
db = ConnectionPool.new(capacity: 25, timeout: 0.01) do
DB.open(ENV["DATABASE_URL"])
end