Skip to content

Instantly share code, notes, and snippets.

@xarimanx
xarimanx / capistrano-tag.txt
Created December 7, 2015 11:47
easily deploy from Git tags
Are you using Capistrano and Git and want to easily deploy from Git tags? It couldn't be simpler
Using Git, tag a new release:
git tag -a 09.10.02.01 -m "Tagging a release"
You can use git tag to list your tags:
git tag
09.10.01.01
09.10.01.02
@xarimanx
xarimanx / gist:8014b5808e20814772ea
Created November 12, 2015 15:16 — forked from AndrewO/gist:1841191
PhantomJS code to dump computed styles of all elements and take a screenshot
[url, height, width, output_dir] = phantom.args
console.log("url #{url}, height #{height}, width #{width}, output_dir #{output_dir}")
page = require('webpage').create()
page.viewportSize =
width: width
height: height
page.onConsoleMessage = (msg) ->
@xarimanx
xarimanx / coffee.rake
Created November 5, 2015 08:10
manual coffee compile
namespace :coffee do
task :compile, :filename do |t, args|
filename = args.filename
puts CoffeeScript.compile(File.open(filename))
end
end
Then, you can compile a single file from like this:
$ rake coffee:compile[app/assets/javascripts/mystuff.js.coffee]
@xarimanx
xarimanx / auto_fixtures.txt
Created October 29, 2015 17:00
auto key for django fixtures
Use "pk: null" instead of "pk: 1" (or whatever), which will result in the PK being set to None, and when the object is saved a primary key will be assigned.
This works for YAML at least, I'm guessing you're using that if you are creating by hand.
@xarimanx
xarimanx / zipper.rb
Created October 13, 2015 15:09
create zip
require 'zip'
# Usage:
# directoryToZip = "/tmp/input"
# outputFile = "/tmp/out.zip"
# zf = ZipFileGenerator.new(directoryToZip, outputFile)
# zf.write()
class ZipFileGenerator
def initialize(inputDir, outputFile)
@inputDir = inputDir
@xarimanx
xarimanx / unzipper.rb
Created October 13, 2015 15:08
extract zip
Zip::ZipFile.open(file_path) do |zip_file|
zip_file.each do |f|
f_path=File.join("destination_path", f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
end
end
@xarimanx
xarimanx / call-apply-bind-proxy.js
Created September 29, 2015 06:33 — forked from branneman/call-apply-bind-proxy.js
JavaScript call() vs apply() vs bind() vs $.proxy()
var fn = function(arg1, arg2) {
var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
document.body.innerHTML += str;
};
var context = {
'noot': 'noot'
};
var args = ['mies', 'wim'];
// Calls a function with a given 'this' value and arguments provided individually.
@xarimanx
xarimanx / rspec.rake
Last active September 18, 2015 13:11 — forked from kamilio/rspec.rake
RSpec::Core::RakeTask.module_eval do
def pattern
dir = EngineName.root # replace with you the name of your engine
extras = []
if File.directory?( dir )
extras << File.join( dir, 'spec', '**', '*_spec.rb' ).to_s
end
[@pattern] | extras
end
end
@xarimanx
xarimanx / executable-with-subcommands-using-thor.log
Last active September 7, 2015 12:46 — forked from sss/executable-with-subcommands-using-thor.log
Revised: Namespacing thor commands in a standalone Ruby executable
$ ./executable-with-subcommands-using-thor.rb
Tasks:
executable-with-subcommands-using-thor.rb help [TASK] # Describe available tasks or one specific task
executable-with-subcommands-using-thor.rb subA [TASK] # Execute a task in namespace subA
executable-with-subcommands-using-thor.rb subB [TASK] # Execute a task in namespace subB
executable-with-subcommands-using-thor.rb test # test in CLI
$ ./executable-with-subcommands-using-thor.rb help
Tasks:
executable-with-subcommands-using-thor.rb help [TASK] # Describe available tasks or one specific task
@xarimanx
xarimanx / user_settings.json
Created September 3, 2015 10:49
Sublime user settings
{
"auto_indent": true,
"bold_folder_labels": true,
"color_scheme": "Packages/User/SublimeLinter/Sunburst (SL).tmTheme",
"draw_indent_guides": true,
"ensure_newline_at_eof_on_save": true,
"folder_exclude_patterns":
[
"log",
".git",