Skip to content

Instantly share code, notes, and snippets.

View sapslaj's full-sized avatar

Justin Roberson sapslaj

View GitHub Profile
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
@public_actions = [:new, :create, :validate, :show, :index]
before_filter :require_login, except: @public_actions
def not_authenticated
@sapslaj
sapslaj / collapsable.coffee
Created June 11, 2015 02:25
Very simple jQuery collapsing thingy
$ ->
$parent = $('.collapsable')
$parent.find('.collapsable-header').click (e) ->
$parent.find('.collapsable-content').slideToggle('slow')
@sapslaj
sapslaj / new.rb
Created June 8, 2015 02:56
How to refactor a Markdown conversion class to a struct
Markdown = Struct.new(:markdown_text) do
class << self
def convert(text)
Markdown.new(text).to_html
end
end
def to_html(renderer_options = {hard_wrap: true, filter_html: true})
renderer_options = {hard_wrap: true, filter_html: true}.merge renderer_options
redcarpet_options = {
@sapslaj
sapslaj / todo.html
Created May 3, 2015 04:46
Qt-like GUI in the browser (CuddleJS)
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="todo_styles.css">
</head>
<body>
<div id="appcontainer"></div>
<script src="cuddle.js"></script>
<script src="todo_item.js"></script>
<script src="todo_list.js"></script>
@sapslaj
sapslaj / some_page.html
Created May 2, 2015 21:31
Tabs, data attributes, and stuff
<ul class="tabs" data-view-template="#some-handlebars-template">
<li data-remote="/some_rest_api/1">First Tab</li>
<li data-remote="/some_rest_api/2">Second Tab</li>
</ul>
<div class="container" id="tab-container">
</div>
@sapslaj
sapslaj / download_railscasts.rb
Last active August 29, 2015 14:17
Download all Railscasts episodes
require 'httparty'
require 'nokogiri'
require 'json'
require 'pry'
class Downloader
def initialize(episode)
system("wget #{episode.direct_link}")
end
end
@sapslaj
sapslaj / controller.coffee
Last active August 29, 2015 14:16
my take on MVC on the client
class ArticleViewController extends ViewController
initialize: (@params) ->
@event.on('button.new-comment', 'click', @new_comment)
@event.on('button.like', 'click', @like)
new_comment: (event) ->
comment_body = $('input.new-comment').val()
comment = new Comment({body: comment_body})
if comment.save()
flash_notice("Comment posted!")
@sapslaj
sapslaj / .vimrc
Last active April 3, 2017 21:29
dotfiles
" based on http://github.com/grigio/vim-sublime
" Best view with a 256 color terminal and Powerline fonts
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-surround'
@sapslaj
sapslaj / digger_map.coffee
Created February 2, 2015 21:50
Basic interface with ROT
require 'map'
class DiggerMap extends Map
_generate: ->
@_create new ROT.Map.Digger()
@sapslaj
sapslaj / .stignore
Last active October 3, 2018 07:25
Syncthing .stignore
// Windows image file caches
Thumbs.db
ehthumbs.db
// Folder config file
Desktop.ini
// Recycle Bin used on file shares
$RECYCLE.BIN/