Skip to content

Instantly share code, notes, and snippets.

View Fustrate's full-sized avatar

Steven Hoffman Fustrate

  • Valencia, CA, USA
View GitHub Profile
@Fustrate
Fustrate / ToxgExpression.php
Created August 17, 2011 02:27
readLangRef() to accept complex language strings
protected function readLangRef()
{
// It looks like this: #xyz.abc[$mno][nilla].$rpg
// Which means:
// x.y.z = x [ y ] [ z ]
// x[y.z] = x [ y [ z ] ]
// x[y][z] = x [ y ] [ z ]
// x[y[z]] = x [ y [ z ] ]
//
// When we hit a ., the next item is surrounded by brackets.
@Fustrate
Fustrate / test.php
Created August 17, 2011 03:34
Find a deep array value given the path as an array. Please tell me this isn't the most efficient way...
<?php
function find_it($key)
{
$preserve_key = $key;
$txt['first']['second']['third']['end'] = 'yay!';
$search = $txt;
while (($part = array_shift($key)) && isset($search[$part]))
// Gets the language string based on index
public function get($key, $replacements = array())
{
if (empty($key))
throw new Core_Exception('lang_empty_index_sent');
if (is_array($key))
{
$preserve_key = $key;
$search = $this->language_strings;
@Fustrate
Fustrate / gist:1201734
Created September 7, 2011 21:08
Potential tpl:format, untested
protected static $format_types = array();
public function tpl_format(ToxgBuilder $builder, $type, array $attributes, ToxgToken $token)
{
$this->requireEmpty($token);
$this->requireAttributes(array('value', 'as'), $attributes, $token);
$value = $builder->parseExpression('normal', $attributes['value'], $token);
$as = preg_replace('~[^a-z_-]~', '', strtolower($attributes['as']));
configuration:
identifier: com.fustrate.tasks
controller: Tasks_Module
routes:
tasks:
visible: Yes
title: tasks
routes:
main:
  1. Install ruby
  2. Install gems: gem install nokogiri snoo
  3. Set a cron job to run update.rb every hour/day/etc.
  4. Add [](/updates) at the top and bottom of the current table/header. Anything inside this pair of links will be replaced.
  5. Update the usernames and password at the top of the file - the account must have config mod permissions
module LoadResources
module ClassMethods
def load_resource(resource_class, options = {})
filter_options = options.slice :only, :except, :if, :unless
resource_options = options.except :only, :except, :if, :unless
send(:before_filter, filter_options) do |controller|
ResourceBuilder.new(controller, resource_class, resource_options)
.send(:load_resource)
end
# Input: "@supports (display: flex) { @media screen and (min-width: 900px) { article { padding: 1rem 3rem; } } }"
[
{
:node=>:at_rule,
:name=>"supports",
:prelude=>[
{:node=>:whitespace, :pos=>9, :raw=>" "},
{
:node=>:simple_block,
# Comments removed for brevity
# No need to declare which submodules are in use beforehand
Rails.application.config.sorcery.configure do |config|
config.not_authenticated_action = :not_authenticated
config.save_return_to_url = true
config.cookie_domain = nil
config.remember_me_httponly = true
config.token_randomness = 15
@Fustrate
Fustrate / prawn-grouping.rb
Created November 11, 2020 03:41
Explicit caching for Prawn PDF images
# frozen_string_literal: true
module Prawn
# `cached_image` needs to know if it's in a cloned document or the original so that it can store
# the image object data properly.
class ClonedDocument < Document
attr_reader :root_document
def initialize(root_document, **options, &block)
@root_document = root_document