Skip to content

Instantly share code, notes, and snippets.

@daveltr
daveltr / scheduler.ex
Created November 9, 2016 21:25 — forked from danielberkompas/scheduler.ex
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.

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
require "dim"
AppContainer = Dim::Container.new
AppContainer.register(:env) { ENV['ADWORK_ENV'] || "development" }
AppContainer.register(:production?) { |c| c.env == 'production' }
AppContainer.register(:development?) { |c| c.env == 'development' }
AppContainer.register(:test?) { |c| c.env == 'test' }
AppContainer.register(:root) { File.expand_path(File.dirname(__FILE__)+"/../..") }
AppContainer.register(:logger) do |c|
RSpec.configure do |config|
config.before(:suite) do
ActiveRecord::Base.establish_connection database['one']
DatabaseCleaner.strategy = :deletion
ActiveRecord::Base.establish_connection config.database['two']
DatabaseCleaner.strategy = :deletion
end
config.before(:each) do
@daveltr
daveltr / jsbin.lusuyiku.css
Last active August 29, 2015 14:00
centered color block hr
.hr-wrapper {
margin-top: 50px;
}
.full-width {
position: absolute;
width: 100%;
border-bottom: 1px solid #ddd;
margin-top: 0px;
}
-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
--
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
tell application "Finder"
set my_file to first item of input
set filetype to (kind of (info for my_file))
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
@daveltr
daveltr / extract_sbf_proof.rb
Created December 25, 2013 15:23
proof of concept extraction of binary data from SBF files.
require 'bindata'
BLOCK_SIZE = 64
class SbfHeader < BinData::Record
endian :little
uint32 :dchain
uint32 :dcount
uint32 :serial
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')

Standard Competition Rankings

This class makes it easier to generate a leaderboard that complies with the Standard Competition Ranking system. That is, it takes joint/tied positions into account, and adjusts the positions accordingly.

Take the following list of users and points for example:

User    | Points
1         35
2         35