Skip to content

Instantly share code, notes, and snippets.

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
View hot_algorithm.md

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") }
View reddit.rb
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
View rotor-elixir-reloading.ex
paths = ["lib/appname/**"]
Rotor.add_group :elixir_reload, paths, fn(files)->
Enum.each files, fn(file)->
Code.load_file(file.path)
end
end
View styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:background">@color/app_bg</item>
<item name="android:actionBarStyle">@style/AppActionBar</item>
</style>
View gist:11391628
== Compilation error on file lib/phoenix/examples/router.ex ==
could not compile dependency phoenix, mix compile failed. You can recompile this dependency with `mix deps.compile phoenix` or update it with `mix deps.update phoenix`
** (CompileError) deps/phoenix/lib/phoenix/examples/router.ex:1: def users_comments_path/1 has default values and multiple clauses, use a separate clause for declaring defaults
(elixir) src/elixir_def.erl:286: :elixir_def.store_each/8
(elixir) src/elixir_def.erl:101: :elixir_def.store_definition/9
(stdlib) erl_eval.erl:657: :erl_eval.do_apply/6
(stdlib) erl_eval.erl:121: :erl_eval.exprs/5
/tmp/build_af8985d4-6c77-4ac3-a850-adbd1bd91562/deps/phoenix/lib/phoenix/examples/router.ex:1: Phoenix.Router.Mapper.__before_compile__/1
@HashNuke
HashNuke / riak.conf
Created Apr 15, 2014
riak disable javascript VMs.
View riak.conf
# along with other config options
javascript.map_pool_size
javascript.reduce_pool_size
javascript.hook_pool_size
@HashNuke
HashNuke / riak-advanced-config-start.txt
Last active Dec 29, 2015
Riak doesn't start when I add an etc/advanced.config. When there's none, it starts fine.
View riak-advanced-config-start.txt
# I'm using Riak v2.0pre7 (latest tagged release from the github repo)
$ cat etc/advanced.config
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
[
{riak_kv, [
{add_paths, ["/Users/akashmanohar/projects/rinket/_build/shared/lib/firebrick/ebin"]}
]}
]
@HashNuke
HashNuke / auto-scroll-explanation.coffee
Last active Dec 21, 2015
Autoscroll implementation in CoffeeScript. From my latest hobby project. If the user is reading history that's way behind, then do not scroll to the latest message. If the user is reading history that's less than 4 lines away from the latest message, then scroll to the latest message.
View auto-scroll-explanation.coffee
# My markup looks like this
#
# <div class="activities">
# <div class="activities-inner-wrapper">
# <div class="activity">something here</div>
# <div class="activity">another thing here</div>
# <div class="activity">Wowowowowwo</div>
# </div>
# </div>
#
View saltstack-digitalocean.md

These are notes for using the "Salt in 60 seconds" tutorial with DigitalOcean - http://www.saltstat.es/posts/quickstart.html

After creating a droplet via their web interface, login with you IP address and the password that is emailed to you.

export IP=your-ip
ssh root@$IP

Install saltstack

curl -L http://bootstrap.saltstack.org | sudo sh -s -- -M stable
View init.el
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
;; under mac, have Command as Meta and keep Option for localized input
(when (string-match "apple-darwin" system-configuration)
(setq mac-allow-anti-aliasing t)
(setq mac-command-modifier 'meta)