Skip to content

Instantly share code, notes, and snippets.

def self.set_recipe_of_day(options = {})
day = options[:day] || Date.today
force = options[:force] || false
old_recipe = Recipe.recipe_of_day(day)
new_recipe = calculate_recipe_of_day(day)
if old_recipe == new_recipe
if force
new_recipe.save!
new_recipe
module Paperclip
class Attachment
class UploadedPath
attr_reader :original_filename, :content_type, :size, :path
def initialize(uploaded_file)
@original_filename = uploaded_file["name"].downcase
@content_type = uploaded_file["content_type"].to_s.strip
@file_size = uploaded_file["size"].to_i
@path = uploaded_file["path"]
@maxlapshin
maxlapshin / gist:884183
Created March 23, 2011 22:32
delayed_reply.erl
-module(smart_server).
-export([start_link/0, init/0, long_request/1]).
start_link() -> gen_server:start_link(?MODULE, [], []).
long_request(Server) -> gen_server:call(Server, long_request).
init() -> {ok, []}.
handle_call(long_request, From, Buffer) ->
@maxlapshin
maxlapshin / yuv_stream.c
Created June 27, 2011 18:06
Convertion of incoming flv stream to stream of YUV frames.
#include "yuv_stream.h"
enum bufferevent_filter_result has_enough_for_flv(struct evbuffer *src);
static void errorcb(struct bufferevent *bev, short what, void *arg);
void readcb(struct bufferevent *bev, void *arg);
int open_cam(char *path);
int open_output(char *path);
flv_tag *read_decoder_config(struct bufferevent *bev);
flv_tag *read_flv_tag(struct bufferevent *bev);
AVCodecContext *new_software_decoder(flv_tag *decoder_config)
{
char decoder_name[] = "h264";
AVCodec *decoder = avcodec_find_decoder_by_name(decoder_name);
// h264_vaapi, h264_vdpau
if(!decoder) {
fprintf(stderr, "Can't open decoder %s\r\n", decoder_name);
return NULL;
}
@maxlapshin
maxlapshin / legal_paper.rb
Created July 14, 2011 09:16
How to replace substitutions in docs file
class Page
def self.repo
@repo ||= Grit::Repo.new(Erlyhub.doc_path)
end
def self.lookup_path(path, lang = nil)
dirname = File.dirname(path)
dirname = nil if dirname == "."
tree = dirname ? (repo.tree / dirname) : repo.tree
module ApplicationHelper
def show_page(page)
@name = page.is_a?(String) ? page : path.path
page = Page.find(page, I18n.locale) if page.is_a?(String)
raise ActiveRecord::RecordNotFound, "no page #{page}" unless page
if !page.text_format?
render :text => page.contents, :content_type => page.mime_type
@maxlapshin
maxlapshin / misultin_proxy.erl
Created August 16, 2011 19:26
Simple proxy that dumps traffic
% ==========================================================================================================
% MISULTIN - Example: Proxy requests to upstream
%
% ==========================================================================================================
-module(misultin_proxy).
-export([start/1, stop/0]).
% start misultin http server
start(Port) ->
inets:start(),
@maxlapshin
maxlapshin / ffmpeg.erl
Created August 29, 2011 19:53
Nitrogen example for ffmpeg frontend
%% -*- mode: nitrogen -*-
-module (index).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").
-include("video.hrl").
main() -> #template { file="./site/templates/bare.html" }.
title() -> "FFmpeg frontend".