Skip to content

Instantly share code, notes, and snippets.

View readysetawesome's full-sized avatar
🏠
Working from home

Chris Becker readysetawesome

🏠
Working from home
View GitHub Profile
@readysetawesome
readysetawesome / _middleware.ts.diff
Created March 14, 2023 00:46
patch to allow setting cloudflare pages access aud from env vars
diff --git a/functions/_middleware.ts b/functions/_middleware.ts
index 9d5ae42..8f46b34 100644
--- a/functions/_middleware.ts
+++ b/functions/_middleware.ts
@@ -1,8 +1,20 @@
import cloudflareAccessPlugin from "@cloudflare/pages-plugin-cloudflare-access";
-export const onRequest = ({ env }) => {
- return cloudflareAccessPlugin({
- domain: "https://timely-tasker.cloudflareaccess.com",
@readysetawesome
readysetawesome / named_scope_subset_helper.rb
Last active December 15, 2015 14:19 — forked from cee-dub/named_scope_subset_helper.rb
I wanted to rework this using new syntax: "subset.should be_a_subset_of(superset, proc)" inspired by https://gist.github.com/cee-dub/623589 which was inspired by https://gist.github.com/zbrock/615961
def should_be_a_subset(superset, records_selected_by_scope, &condition)
flunk "Your superset is empty" if superset.empty?
flunk "Your scope did not select any records" if records_selected_by_scope.empty?
records_selected_by_block, records_excluded_by_block = superset.partition(&condition)
flunk "Your test condition did not select any records" if records_selected_by_block.empty?
flunk "Your test condition did not exclude any records" if records_excluded_by_block.empty?
records_selected_by_scope.map(&:id).should =~ records_selected_by_block.map(&:id)
end
@readysetawesome
readysetawesome / should_receive_chain.rb
Last active December 14, 2015 09:08
This is great for testing chained scopes in rails, which I think really should be this simple.
class ChainedMock < RSpec::Mocks::Mock
class WrongMethodCalled < StandardError; end
def method_missing meth, *args, &block
raise WrongMethodCalled.new "expected method #{@next} to be next in the chain, but instead received #{meth}"
end
def should_receive(meth, opts = {}, &block)
@next = meth
super
@readysetawesome
readysetawesome / d2g.sh
Last active December 13, 2015 23:29
Turn the current directory's diff into a gist with a single .diff file (assumes you have osx with "pbcopy" and ruby)
function d2g() {
if [ -z "`git diff`" ] ; then
echo 'There is no diff to publish, brah.'
return
fi
if [ $# -eq 0 ] ; then
echo 'Please provide a name for the file.'
return
fi
curl -H "Authorization: token XXXXtokenWithGistScopeXXXX" -d "{\"description\":\"diff for branch: `git branch | grep \* | sed s/\*\ //g`, created: `date`\",\"public\":false,\"files\":{\"$1.diff\":{\"content\":\"`ruby -e 'require "rubygems";require "json";puts JSON.dump(\`git diff\`)[1..-2]'`\"}}}" https://api.github.com/gists | grep '^ "html_url": "https://gist.github.com' | sed s/\ \ \"html_url\"\:\ \"//g | sed s/\",// | pbcopy
@readysetawesome
readysetawesome / best_prompt_evar.sh
Created October 7, 2012 16:40
Color coded bash prompt showing GIT repository name, branch name, working directory state (clean/dirty)
export PS1='$(git branch &>/dev/null; if [ $? -eq 0 ]; then \
echo "\[\e[0;32m\][GIT: \[\e[0;31m\]$(basename `pwd`); \[\e[0;33m\]$(git branch | grep ^*|sed s/\*\ //) \
$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; if [ "$?" -eq "0" ]; then \
echo "\[\e[0;32m\]clean"; else \
echo "\[\e[0;31m\]dirty"; fi)\[\e[0;32m\]] \$ "; else \
echo "\[\e[0;31m\][\w]\[\e[m\] \$ "; fi) \[\e[0m\]'
@readysetawesome
readysetawesome / dj_smtp.diff
Created June 27, 2012 23:16
Django 1.3 vs stable smtp setup differences
index bb184ab..18437c6 100644
--- a/a
+++ b/a
@@ -18,8 +18,14 @@ class EmailBackend(BaseEmailBackend):
super(EmailBackend, self).__init__(fail_silently=fail_silently)
self.host = host or settings.EMAIL_HOST
self.port = port or settings.EMAIL_PORT
- self.username = username or settings.EMAIL_HOST_USER
- self.password = password or settings.EMAIL_HOST_PASSWORD
+ if username is None:
@readysetawesome
readysetawesome / lfsp_invoke.js
Created April 3, 2012 00:28 — forked from nerd0/gist:2176155
Invocation of Livefyre commenting and Livefyre Simple Profiles (bolt-on for existing init)
var engage = new fyre.sp.app.Engage({app: '{!! name of your engage app here !!}');
var profiles = new fyre.sp.app.Profile({});
var delegates = {
'handle_auth_login': function() {
engage.signIn();
},
'handle_auth_logout': function() {
engage.signOut();
@readysetawesome
readysetawesome / joomla_falloff.diff
Created February 28, 2012 17:56
Make comments "fall off" in Joomla plugin
-<script type="text/javascript">var livefyre_blogtype='joomla';</script>
+<script type="text/javascript">
+ var livefyre_blogtype='joomla';
+ var customLivefyreDelegates = {
+ handle_comment_shown: function(data) {
+ var max_comment_length = 200,
+ cid = data.comment.attr('comment_id'),
+ models = LF.Comments.models,
+ len = models.length;
+ if (len > max_comment_length) {
@readysetawesome
readysetawesome / livefyre_sync.php
Created January 29, 2012 00:21
Livefyre's WordPress/PHP sync mechanism
<?php
//on page load the "is this a postback?" filter function runs:
function livefyre_comment_update() {
if (isset($_GET['lf_wp_comment_postback_request']) && $_GET['lf_wp_comment_postback_request']=='1') {
livefyre_do_sync();
// Instruct the backend to use the site sync postback mechanism for future updates.
echo "{\"status\":\"ok\",\"message\":\"sync-initiated\"}";
exit;