Skip to content

Instantly share code, notes, and snippets.

View HashNuke's full-sized avatar
💭
Life happened. I now have varied interests. I may be slow to respond.

Akash Manohar HashNuke

💭
Life happened. I now have varied interests. I may be slow to respond.
View GitHub Profile
We couldn’t find that file to show.
@HashNuke
HashNuke / newairapp.sh
Created February 17, 2010 06:20
Script to generate a skeletal AIR application
#!/bin/sh
#Script to generate a skeletal HTML AIR application
#Copyright (C) 2010 Akash Manohar J (akashxav.com)
#
#Instructions:
#add <air_sdk>/bin to path (skip this if you did when you installed AIR SDK)
#save file as newairapp in the <air_sdk>/bin
#chmod+x <air_sdk>/bin/newairapp
#usage: newairapp <app_name>
#example: newairapp HelloAir
defmodule Mix.Tasks.Phoenix.Release do
use Mix.Task
@shortdoc "Creates a release using exrm"
def run(args) do
Application.put_env(:phoenix, :serve_endpoints, true, persistent: true)
Mix.Task.run "release", args
end
end
@HashNuke
HashNuke / circle-ci-elixir-config
Created June 15, 2015 13:02
expected CircleCI config-for-elixir
machine:
environment:
PATH: "$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"
services:
- redis
dependencies:
cache_directories:
- ~/.asdf
pre:
- if ! asdf | grep version; then git clone https://github.com/HashNuke/asdf.git ~/.asdf; fi
defmodule Tryout do
def hello(name \\ "akash")
def hello(name) do
IO.puts name
end
end
Tryout.hello #=> akash
Tryout.hello("nuke") #=> nuke
@HashNuke
HashNuke / fantastic_rotors.ex
Created October 4, 2014 04:53
INCOMPLETE - WORK IN PROGRESS. Supposed to be used as Fantastic.Rotors.start(options)
defmodule Fantastic.Rotors do
import Rotor.BasicRotors
import CoffeeRotor
import SassRotor
# NOT TESTED won't work
# TODO digested output has to be stored in the application env, as a map, so that it's accessible in the templates.
# so the hash would contain %{"file name" => "digest"}
Rotor.watch :all_files_in_project_root, ["*"], fn(changed, all)->
IO.inspect "CHANGED FILES"
IO.inspect changed
IO.inspect "ALL FILES"
IO.inspect all
end
# Options can be passed as a 4th arg after the rotor function.
# Currently available option is `interval`.
# Default polling interval is 2500 (2.5 seconds).

A sorting algorithm for sorting by "hotness", roughly based on Reddit's algorithm with a few tweeks.

scope :order_by_hot, ->
  { order("round((votes_count - 1) / POW(DATE_PART('day', Now() - created_at) * 24 + DATE_PART('hour', Now() - created_at) + 2, 1.5)::numeric, 8) DESC, votes_count DESC") }
class Story < ActiveRecord::Base
# make likes count whatever basic score you want. it would be the sum of up plus down votes, or use whatever cache counters you have and weight them accordingly.
#the magic time should just be a unix time right before people started making stuff, for us, its just 6 months before we started makr.io
def self.ranked
order("(ln( 1 + posts.likes_count) + (EXTRACT(EPOCH FROM created_at) - 1327654606)/9000) desc")
end
paths = ["lib/appname/**"]
Rotor.add_group :elixir_reload, paths, fn(files)->
Enum.each files, fn(file)->
Code.load_file(file.path)
end
end