Skip to content

Instantly share code, notes, and snippets.

View wkjagt's full-sized avatar

Willem van der Jagt wkjagt

  • Shopify
  • Oka (Montreal area)
View GitHub Profile
<?php
// setup a template loader used by Twig to load the template strings. Most common is loading
// templates from the file system. This loader needs takes a template path or an array of
// template paths as argument to its constructor.
$templatePath = __DIR__.'/templates';
$loader = new Twig_Loader_Filesystem($templatePath);
// setup the twig environment. This is used for the actual rendering. The Twig environment takes
// the loader and an array of options as its arguments. In this example I use the twig environment
require 'net/http'
module Net
class HTTP
def self.enable_debug!
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development'
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)
@wkjagt
wkjagt / 2048.rb
Last active August 29, 2015 14:19
2048 in Ruby, because my daughter was sick, and I stayed in bed with her.
require 'io/console'
class Board
X, Y = 0, 1
COLORS = [:red, :green, :brown, :magenta, :cyan]
HOR_LINE = "-" * 29
EMPTY_COL = "| " * 4 + "|"
def initialize
@score = 0
@wkjagt
wkjagt / percentage_support.md
Last active August 29, 2015 14:22
A readable way to express percentage calculations

Adds a readable way of expressing percentage calculations.

TL;DR

200 - 15.percent # 170

PercentageSupport

Is this a bad idea?

module Decorate
  def decorate(definition, options)	
		self.send(:alias_method, "__original_#{definition}", definition)
		define_method definition, Proc.new { |*args|
			send(options.fetch(:with), *args, &Proc.new { |args|
				send("__original_#{definition}", *args)
 })
@wkjagt
wkjagt / ruby-memoize.md
Last active September 29, 2015 17:45
Ruby Memoize

Memoize memoizes function return values based on class name, method name, and arguments. This means that this only works for functions that use state / have side effects.

module Memoize
  def memoize(definition)	
    self.send(:alias_method, "__original_#{definition}", definition)

    define_method definition, Proc.new { |*args|
 @__memo ||= {}
# This is an h1
## This is an h2
Here is a paragraph with *some bold italics* and some **bold text**.
This paragraph is a little harder because it had **a bold sentence *with some italics* to make it more difficult.**
And finally a [link to shopify](http://shopify.com).
@wkjagt
wkjagt / remove_script_tags.php
Last active November 12, 2020 06:26
Remove script tags from html
<?php
function removeDomNodes($html, $xpathString)
{
$dom = new DOMDocument;
$dom->loadHtml($html);
$xpath = new DOMXPath($dom);
while ($node = $xpath->query($xpathString)->item(0)) {
$node->parentNode->removeChild($node);
}
.segment "HEADER"
.byte "NES", $1A ; Constant
.byte 2 ; 2 x 16KB PRG ROM
.byte 1 ; 1 x 8KB CHR ROM
.segment "CHARS"
;-------------------------------------------------------------
; CREATE SPRITES
;-------------------------------------------------------------
; The following creates one sprite. The following two bitmaps
; ___ _ __ ___ __ ___
; / __|_ _ __ _| |_____ / /| __|/ \_ )
; \__ \ ' \/ _` | / / -_) _ \__ \ () / /
; |___/_||_\__,_|_\_\___\___/___/\__/___|
; An annotated version of the snake example from Nick Morgan's 6502 assembly tutorial
; on http://skilldrick.github.io/easy6502/ that I created as an exercise for myself
; to learn a little bit about assembly. I **think** I understood everything, but I may
; also be completely wrong :-)