Skip to content

Instantly share code, notes, and snippets.

Gavin Kistner Phrogz

Block or report user

Report or block Phrogz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Phrogz
Phrogz / test.js
Created Nov 19, 2018
Serializing a DOM with an attribute created in an existing namespace
View test.js
doc = (new DOMParser).parseFromString('<r xmlns="uri1" xmlns:xx="uri2"><b/></r>', 'text/xml');
doc.querySelector('b').setAttributeNS('uri2', 'foo', 'bar');
(new XMLSerializer).serializeToString(doc);
// "<r xmlns="uri1" xmlns:xx="uri2"><b xmlns:ns14641696="uri2" ns14641696:foo="bar"/></r>"
doc = (new DOMParser).parseFromString('<r xmlns="uri1" xmlns:xx="uri2"><b/></r>', 'text/xml');
doc.querySelector('b').setAttributeNS('uri2', 'xx:foo', 'bar');
(new XMLSerializer).serializeToString(doc);
// "<r xmlns="uri1" xmlns:xx="uri2"><b xx:foo="bar"/></r>"
@Phrogz
Phrogz / ƒ.js
Last active Nov 13, 2018
A useful JS function for running maps on objects; similar to Ruby's Symbol#to_proc &:foo syntax, but more powerful.
View ƒ.js
function ƒ(name){
let v,params=Array.prototype.slice.call(arguments,1);
return o=>(typeof (v=o[name])==='function' ? v.apply(o,params) : v);
}
a = ["foo", "barmitzvah"]
a.map(ƒ('length')) // [3, 10]
a.map(ƒ('toUpperCase')) // ["FOO", "BARMITZVAH"]
a.map(ƒ('slice',1)) // ["oo", "armitzvah"]
@Phrogz
Phrogz / example.js
Created Nov 11, 2018
Showcasing some of NeatSerializer's features
View example.js
let xml =
`<r a="42" xmlns:blah="MYURI">
<e> <!-- my house --> </e>
<f>9&lt;42</f>
<blah:dumb>go away</blah:dumb>
<g><![CDATA[5<7]]></g>
</r>`;
let doc = (new DOMParser).parseFromString(xml, 'application/xml');
console.log(NeatSerializer(doc));
@Phrogz
Phrogz / intercept.js
Created Nov 10, 2018
Intercepting JavaScript prototypal inheritance
View intercept.js
let p = console.log;
let Interceptor = { hi:_=>"I am "+this.name }
function Person(name) {
this.name = name;
}
Person.prototype.hi = function() {
return "Hello, I'm "+this.name
}
@Phrogz
Phrogz / funcenv.lua
Last active Nov 5, 2018
Evaluating the same expression in multiple environments, dynamically
View funcenv.lua
-- An expression to evaluate
local expr = 'a + (b or 0)'
-- Set up two different environments we want our expression to be evaluated against
local env1,env2 = {a=17}, {a=1,b=25}
-- Create a wrapper environment with a metatable
local envmeta = {}
local envwrap = setmetatable({},envmeta)
@Phrogz
Phrogz / app.lua
Last active Oct 31, 2018
Overriding Lua libraries with stub versions, that have access to the originals
View app.lua
-- add my custom lib directory to the path
package.path = 'lib/?.lua;'..package.path
-- add this line only to switch to using the wrappers;
-- do this after making any other path adjustments.
package.real,package.path = package.path,'debug/?.lua;'..package.path
local mylib = require 'mylib'
View PishTemplate.rb
require 'parslet'
class PishTemplate < Parslet::Parser
attr_accessor :vars
# `vars` is a hash of symbol-to-values for referencing in templates.
# vars can also be safely set using the #assign-values method.
def initialize(vars={})
super()
@vars = vars
View SimpleParse.rb
class SafeTemplate < Parslet::Parser
# ...
rule(:cond) do
test.as(:test) >> markup.as(:out)
>> (elif.as(:test) >> markup.as(:out)).repeat.as(:elifs)
>> (ells >> markup.as(:elseout)).maybe
>> stop
end
# ...
end
@Phrogz
Phrogz / LICENSE.md
Last active Oct 4, 2017 — forked from ganezasan/LICENSE.md
Day / Hour Heatmap in v4
View LICENSE.md

Copyright (c) 2016, Tom May

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTH

View remove-qmapbox.patch
index 0dd8c96..b28aebf 100644
--- a/platform/qt/qmlapp/main.cpp
+++ b/platform/qt/qmlapp/main.cpp
@@ -1,5 +1,3 @@
-#include <QMapbox>
-
#include <QGuiApplication>
#include <QIcon>
#include <QQmlApplicationEngine>
@@ -13,10 +11,6 @@ int main(int argc, char *argv[])
You can’t perform that action at this time.