Skip to content

Instantly share code, notes, and snippets.

View myobie's full-sized avatar

Nathan myobie

View GitHub Profile
<?php
make_embed_params_tag_params()
{
// the valid params for the tag
$valid_params = array(
'entry_id',
'weblog_id',
'url_title'
);
var DiffJSON = (function() {
var isObject = function(obj) {
return Object.prototype.toString.apply(obj) == "[object Object]";
};
var retrieve = function(nested_key) {
var keys = nested_key.split("."), current_object = this;
for (var i = 0; i < keys.length; i++) { current_object = current_object[keys[i]] }
return current_object;
@myobie
myobie / scope.rb
Created September 28, 2010 01:25
module Scope
module ScopeMethods
def helpers(&block)
instance_eval(&block)
end
end
def scope(path, &block)
(@path_parts ||= []) << path
@scottwb
scottwb / README.md
Created February 6, 2012 20:45
Monkey patches for a couple Rails Mime::Type.parse bugs.

Rails Mime::Type.parse Patches

There are two Rails issues in it's handling of the HTTP Accept header which cause a number of spurious exception emails via Airbrake. I am encountering this on Rails 3.0.7. One of these is fixed in a later version of Rails, but for other reasons I can't upgrade right now. The other bug is still present in Rails 3.2 and in master at the time of this writing. This gist includes some monkey patches you can apply to fix these issues until such time that they are fixed in Rails properly.

Rails Issue #736

Issue #736 is that Rails does not correctly parse a q-value in an Accept header when there is only one content-type specified. For example:

Accept: text/html;q=0.9
def set_locale
locale = params[:locale].to_s
if !locale.blank?
cookies[:preferred_lang] = { :value => locale, :expires => 10.years.from_now }
session[:update_lang] = locale # remember preferred setting for this session
else
locale = cookies[:preferred_lang]
end
$nonpareille: 8px!default;
$minion: 9px!default;
$petit: 11px!default;
$bourgeois: 12px!default;
$long-primer: 13px!default;
$small-pica: 15px!default;
$pica: 16px!default;
$english: 19px!default;
$columbian: 21px!default;
$great-primer: 24px!default;
@BinaryMuse
BinaryMuse / phantom.coffee
Created April 13, 2012 18:33
Take screenshots with Phantom.js from Node.js
#!/usr/bin/env coffee
# Call the program with: coffee phantom.coffee http://url.to/screengrab
phantom = require 'phantom' # npm install phantom
child_process = require 'child_process'
url = process.argv[2]
createScreenshot = (page, filename) ->
@mislav
mislav / fat-logfiles.sh
Last active December 22, 2018 19:56
Find "*.log" files in your home dir, sort them by fattest-first, and calculate the size of them all together.
find ~ -name '*.log' -print0 | xargs -0 -L1 stat -f'%z %N' | sort -rn | tee fat-logfiles.txt | head
awk '{ total += $1 } END { printf "total: %5.2f MiB\n", total/1024/1024 }' < fat-logfiles.txt
@myobie
myobie / slugify.sql
Created June 1, 2019 16:19 — forked from kez/slugify.sql
Generating Slugs in Postgres
CREATE EXTENSION IF NOT EXISTS "unaccent"
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
-- removes accents (diacritic signs) from a given string --
WITH "unaccented" AS (
SELECT unaccent("value") AS "value"
),
-- lowercases the string
"lowercase" AS (
@danielberkompas
danielberkompas / scheduler.ex
Created October 26, 2016 17:59
A simple mix task scheduler for Elixir apps
defmodule MyApp.Scheduler do
@moduledoc """
Schedules a Mix task to be run at a given interval in milliseconds.
## Options
- `:task`: The name of the Mix task to run.
- `:args`: A list of arguments to pass to the Mix task's `run/1` function.
- `:interval`: The time interval in millisconds to rerun the task.