Skip to content

Instantly share code, notes, and snippets.

View dannguyen's full-sized avatar
💭
havin a normal one

Dan Nguyen dannguyen

💭
havin a normal one
View GitHub Profile
@dannguyen
dannguyen / forgittin-these-gits.sh
Created April 25, 2013 17:42
Git commands that I keep forgittin
# set default pull target
# http://stackoverflow.com/questions/658885/how-do-you-get-git-to-always-pull-from-a-specific-branch
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
@dannguyen
dannguyen / instructions-for-subtitles.md
Last active June 9, 2016 18:47
Reading subtitles

Given a MP4 file...

Use MP4Box to extract into VOB/SUB format

First, find the info: /Volumes/GPAC\ for\ OSX/Osmo4.app/Contents/MacOS/MP4Box -info ~/Desktop/MOVIEFILE.m4v

  * Movie Info *
    Timescale 90000 - Duration 00:22:36.981

4 track(s)

@dannguyen
dannguyen / twitter-oauth.rb
Created June 13, 2013 14:28
Generating Twitter app credentials at the command line
require 'rubygems'
require 'twitter_oauth'
require 'json'
client = TwitterOAuth::Client.new(
:consumer_key => 'THEKEY',
:consumer_secret => 'THESECRET'
)
request_token = client.authentication_request_token( :oauth_callback => 'oob')
@dannguyen
dannguyen / gem-boilerplate-stuff.rb
Last active December 20, 2015 18:38
Things for newly made gems to be incorporated later
#### spec/spec_helper.rb
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
# Rails Engine call
`rails plugin new MY_ENGINE --dummy-path=spec/dummy --skip-test-unit --full --database=mysql`
or `rails plugin new ENGINE_NAME --dummy-path=spec/dummy --skip-test-unit --mountable --database=mysql`
# Configure spec_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require 'rspec/rails'
@dannguyen
dannguyen / gist:6595597
Last active January 18, 2019 17:49
Running rails engine with rspec
# http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
rails plugin new my_engine --dummy-path=spec/dummy --skip-test-unit --mountable
# or, the full monty:
rails plugin new active_scraper --mountable --dummy-path=spec/dummy --skip-test-unit --skip-javascript --skip-sprockets --skip-action-view
# https://github.com/rspec/rspec-rails
rails generate rspec:install
@dannguyen
dannguyen / fb-feed-to-csv.rb
Last active December 24, 2015 22:39
Convert facebook feed to flat array and discard large fields
require 'json'
feed_owner_id = feed_array.first['id'].split('_')[0]
vals = feed_array.map do |post|
next if post.nil? || post.empty?
hsh = {}
if !post['from']
hsh[:from] = 'N/A'
elsif post['from']['id'] != feed_owner_id
@dannguyen
dannguyen / string-cleaning.rb
Created October 23, 2013 12:15
funny string cleaning
class String
def astrip
self.gsub(/([\302|\240|\s|\n|\t])|(\ ?){1,}/, ' ').gsub("\240",' ').ostrip
end
def clean_chars
self.clean_dashes.clean_funny_spaces
end
@dannguyen
dannguyen / regex-indented-markdown-replacement.md
Created January 27, 2014 20:18
Regex to wrap indented markdown with Github-flavored syntax

Find:

  ((?:^\n)(?:^\s{4,}.*)\n(?:^(?:\s{4,}.*\n|\n))*?(?=^\S))

Replace

  \n```ruby\n$1\n```\n\n
@dannguyen
dannguyen / erb-to-slim-kindof.rb
Last active August 29, 2015 13:56
Prepare ERB for SLIM
# Not great, but better than doing everything by hand...
def prepare_erb_for_slim(body)
# remove all %>
body.gsub!(/%> */, '')
# convert <%-/= to -
body.gsub!(/<%(-|=) */, '\1 ')