Skip to content

Instantly share code, notes, and snippets.

View tastycode's full-sized avatar

Sasha Devol tastycode

  • Elsewhere Labs
  • New Orleans, LA
View GitHub Profile
@tastycode
tastycode / nested_regex.rb
Created September 9, 2012 16:22
blog_snips
require 'english'
main_path = %r{/status/(?<code>\d+)}
format_path = %r{#{main_path}\.?(?<format>html|json)}
format_path =~ "/status/500.json"
$LAST_MATCH_INFO[:code] # => "500"
$LAST_MATCH_INFO[:format] # => "json"
matches = format_path.match "/status/500.json"
matches[:code] # => "500"
@tastycode
tastycode / terminal.markdown
Created January 25, 2013 12:02
Terminal Safe JSON

If you could use JSON in the terminal, then applications would have a uniform way of passing in options.

ls [long, {sort: {size: -1}}]

grep [recursive, color]

If we could intercept arguments to commands, we could translate them into the corresponding flags.

The problem is that terminals don't like these characters.

url = "http://www.google.com"
rex = %r{^(\w+)*://(\w+)?\.(\w+).?\.(\w+)}
url.match(rex)
url_data = {:host => $1, :hostname => $2, :domain => $3, :tld => $4}
p url_data # {:host=>"http", :hostname=>"www", :domain=>"google", :tld=>"com"}
@tastycode
tastycode / vimrc.after
Last active December 14, 2015 09:39
~/.vimrc.after for use with janus
if has("gui_running")
set guioptions=egmrt
endif
" so we don't have to use that extra key when we use commands
map ; :
" molokai colorscheme
colo molokai

Ruby/Python Number Conversion Chart

Ruby
From To Python
@tastycode
tastycode / gist:5946805
Created July 8, 2013 07:16
paste this into your address bar
data:text/html, <html><style>* { color: #f00 }</style><body>meow<a href="data:text/html, <html><style> * { color: #00f}</style><body>bark<a href='javascript:window.history.go(-1)'>go</a></body></html>">go</a></body></html>
@tastycode
tastycode / gist:6499842
Created September 9, 2013 18:49
Sniff out references to symbols in perform methods for resque
it "does not have any symbols" do
perform_source = described_class.method(:perform).source
tokens = Ripper.lex(perform_source).map {|token| SyntaxToken.new(token) }
potential_symbols = ObjectRegex.new('symbeg (ident | kw)').all_matches(tokens)
if potential_symbols.any?
potential_symbols.flatten.each do |token|
next unless token.type == :on_symbeg
source_line = perform_source.lines.to_a[token.line - 1]
warn "Potential symbol found on column #{token.col} of #{described_class}#perform"
warn source_line
(ns shorty-clojure.handler
(:use compojure.core)
(:use ring.util.response)
(:require [compojure.handler :as handler]
[compojure.route :as route]
[ring.util.response :as resp]
[ring.middleware.json :as middleware]
[taoensso.carmine :as car :refer (wcar)]))
@tastycode
tastycode / angular service
Created April 10, 2014 19:59
Deferred Event Queue Patterns
'use strict';
angular.module('rallyApp')
.service('EventQueue', function EventQueue($q) {
var eventQueues = {};
var listeners = {};
var triggerEvent = function(queue, event, listener) {
queue.splice(queue.indexOf(event), 1);
listener.cb(event);
@tastycode
tastycode / gist:90a8b38e11be463669ba
Created May 1, 2014 18:08
Convert $http promise to regular promise
Article.prototype.comments = function() {
var url = RouteIndex.comments($scope.article.id).relative();
var deferred = $q.defer();
$http.get(url).success(function(comments) {
deferred.resolve(comments);
});
return deferred.promise;
};
//usage