Skip to content

Instantly share code, notes, and snippets.

View ThisIsMissEm's full-sized avatar

Emelia Smith ThisIsMissEm

View GitHub Profile
@ThisIsMissEm
ThisIsMissEm / output.rb
Last active August 29, 2015 14:10
Is there a more efficient way of doing this? Show.tag is assumed to be unique.
Show.select(:id, :tag).reduce({}) do |index, show|
index[show[:tag]] = show[:id]
index
end
# Print log messages to the console,
# can also be done by passing the -v option to liquidsoap.
set("log.file.path","/tmp/<script>.log")
set("log.stdout", true)
# Socket control
set("server.socket",true)
set("server.socket.path","/tmp/liquidsoap-socket")
set("server.timeout",-1.0)
@ThisIsMissEm
ThisIsMissEm / posts_controller.rb
Created January 12, 2015 03:59
Idea is to allow a relative path to be supplied to which the user is redirected after update. For instance, to redirect to another action, or back to the list they came from. Should be safe from Unvalidated redirects: https://www.owasp.org/index.php/Unvalidated_Redirects_and_Forwards_Cheat_Sheet
class PostsController < AdminController
# ... snip ...
def update
if @post.update(post_params)
redirect_to url_for_redirect
else
render :show
end
@ThisIsMissEm
ThisIsMissEm / Example outputs:
Created April 4, 2015 00:50
Spent some time trying to get really decent logs out of the ruby AWS SDK
On Success:
[aws] [dynamodb] operation=put_item duration=0.042833 retries=0 error=false
On Error:
[aws] [dynamodb] operation=put_item duration=25.555756 retries=10 error=true
Note: I've only tested this with Dynamodb, but I suspect it should work for most of the AWS APIs
import React from 'react';
export default class AudioPlayer extends React.Component {
constructor() {
super();
this.state = {};
}
componentDidMount() {
this.audio = document.createElement('audio');
@ThisIsMissEm
ThisIsMissEm / dAmnViper.jsm
Created June 18, 2015 22:43
Here's some code I wrote circa 2008/09, I blogged about what I was working on at the time, but what I wrote, I'm sure was lost long ago. I don't claim that this code is good by any means, but it was certainly the precursor to my love for Node.js and async network i/o.
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
@ThisIsMissEm
ThisIsMissEm / nginx.conf
Last active August 29, 2015 14:25
Ever needed to re-route static files dynamically for nginx? This configuration allows you to map keys in redis to files on disk. Why might you want to do this? Think ephemeral signatures on content. Alternatively, you could always use lua directly to verify content signatures and expiries
worker_processes 2;
error_log /var/log/nginx/openresty-error.log info;
events {
worker_connections 1024;
}
http {
server {
listen 8000;
$('a[href^=#]').bind('click', function(e){
e.preventDefault();
var target = $(this).attr('href');
if(target !== "#"){
target = $(target);
$('html').animate({scrollTop: target.scrollTop() + target.offset()['top']}, 500);
}
return false;
});
$ git push origin master
>> To git@github.com:Miksago/Jet.js.git
>> ! [rejected] master -> master (non-fast forward)
>> error: failed to push some refs to 'git@github.com:Miksago/Jet.js.git'
-----------------------------------------------------------------------------------------------------------------
Property / Method | Access | Type | Arguments | Returns
------------------------------------------------------------------------------------------------------------------
Jet
_uri private
base Function() String
loaded Function() Array
resolve Function Namespace String
_namespaces private Object Object