Skip to content

Instantly share code, notes, and snippets.

@fooqri
fooqri / nokogiri_greyhound_search
Created February 17, 2012 03:36
Ruby Nokogiri usage example
@fooqri
fooqri / ImageToMMD.bash
Created December 17, 2012 19:55
TextExpander snippet for saving clipboard image to disk and writing markdown link for it.
#!/usr/bin/env bash
uuid_str=$(/usr/local/bin/uuid)
dir="/Users/my-account/my-wiki/images/"
target="$dir$uuid_str.png"
var=$(/usr/local/bin/pngpaste $target 2>&1)
if [ "$var" == "No PNG data found on the clipboard!" ];
then
echo "No-PNG"
else
echo "[![$uuid_str.png](images/$uuid_str.png)](images/$uuid_str.png)"
require 'graphviz'
# Create a new graph
g = GraphViz.new( :G, :type => :digraph )
us_num = 47 #placeholder, will get from file name in final version.
# set global node options
g.node[:color] = "#333333"
g.node[:style] = "filled"
g.node[:shape] = "box"
@fooqri
fooqri / list_example.rb
Last active April 2, 2017 15:20
Simple example of a checklist using ruby state_machine gem
require 'rubygems'
require 'state_machine'
class Item
attr_accessor :name, :description
state_machine :item_state, :initial => :available do
after_transition :available=> :completed, :do => :item_completed
require 'goliath'
require 'em-synchrony'
require 'em-synchrony/em-mongo'
require 'grape'
require './app/models/mission.rb'
require './app/models/player.rb'
module MyAppName
class API_v1 < Grape::API
prefix 'api'
@fooqri
fooqri / mdlist_parser.rl
Created January 19, 2013 17:05
A simple Ragel example for parsing a markdown style list.
class MDListParser
attr_accessor :lists
%%{
machine test_lexer;
action MarkTaskStart {
task_start = fpc
@fooqri
fooqri / lists.txt
Last active December 11, 2015 08:29
A simple Ragel example for parsing a markdown styled todo list.
## Tasks
- Go to Whole Foods
- Go to produce section
- get oranges
maybe Mandarine and Valencia
- get avocados
- get squash
maybe buttercup if they have it
- Go to bakery section
- get bagels
@fooqri
fooqri / lists.txt
Created January 19, 2013 17:14
A simple list for a Ragel example
## Tasks
- Go to Whole Foods
- Go to produce section
- get oranges
maybe Mandarine and Valencia
- get avocados
- get squash
maybe buttercup if they have it
- Go to bakery section
- get bagels
@fooqri
fooqri / app_delegate.rb
Last active December 12, 2015 06:59
Excerpt from app delegate for setting up RestKit logging. I was getting an undefined constant error for RKLogConfigureByName, the standard way of setting up logging in restkit. It seems that the #define statements in /vendor/Pods/RestKit/Code/Support/RKLog.h are not getting picked up. I will need to investigate further but this quick workaround …
def init_restkit_logging
#define RKLogLevelOff -> RKlcl_vOff
#define RKLogLevelCritical -> RKlcl_vCritical
#define RKLogLevelError -> RKlcl_vError
#define RKLogLevelWarning -> RKlcl_vWarning
#define RKLogLevelInfo -> RKlcl_vInfo
#define RKLogLevelDebug -> RKlcl_vDebug
#define RKLogLevelTrace -> RKlcl_vTrace
# "restkit" "RestKit"
@fooqri
fooqri / gist:5691402
Created June 1, 2013 19:10
init.el excerpt
(defun quick-copy-line ()
"Copy the whole line that point is on and move to the beginning of the next line.
Consecutive calls to this command append each line to the
kill-ring."
(interactive)
(let ((beg (line-beginning-position 1))
(end (line-beginning-position 2)))
(if (eq last-command 'quick-copy-line)
(kill-append (buffer-substring beg end) (< end beg))
(kill-new (buffer-substring beg end))))