Skip to content

Instantly share code, notes, and snippets.

View qw3r's full-sized avatar

István Demeter qw3r

  • Emarsys
  • 08:04 (UTC +02:00)
View GitHub Profile
simpleFormat = (text) ->
re1 = /\r\n?/g
re2 = /\n\n+/g
re3 = /([^\n]\n)(?=[^\n])/g
fstr = text
fstr = fstr.replace(re1, "\n") # \r\n and \r -> \n
fstr = fstr.replace(re2, "</p>\n\n<p>") # 2+ newline -> paragraph
fstr = fstr.replace(re3, "$1<br/>") # 1 newline -> br
"<p>#{fstr}</p>"
@qw3r
qw3r / drop_connections.rake
Created November 13, 2012 15:10 — forked from trekdemo/drop_connections.rake
Drop postgres connections to a database in a Rails application
namespace :db do
desc 'Drop all database connections'
task :drop_connections => :environment do
database = Rails::Application.config.database_configuration[RAILS_ENV]["database"]
field = if ActiveRecord::Base.connection.send( :postgresql_version ) < 90200
'pg_stat_activity.procpic' # PostgreSQL <= 9.1.x
else
'pg_stat_activity.pid' # PostgreSQL >= 9.2.x
end
@qw3r
qw3r / j_unit.rb
Created November 10, 2012 10:50 — forked from natritmeyer/Usage.txt
JUnit formatter for RSpec
=begin
Copyright (c) 2012, Nathaniel Ritmeyer
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@qw3r
qw3r / gist:2187397
Created March 24, 2012 20:07
simple way to show form as description list using twitter bootstrap
module ApplicationHelper
def definition_lists_for(model, &block)
dl = DefinitionListHelper.new model
yield dl
end
class DefinitionListHelper
include ActionView::Helpers
include ActionView::Context
include Haml::Helpers
@qw3r
qw3r / fuckyeah
Created September 20, 2011 22:22
backup LVM backed iSCSI target
I've created a san using Logical Volumes as backing-store iSCSI LUNs (tgt)
the target iqn.2011-09.com.pany.san:target1 using the LV /dev/vg0/t1l1 as backing-store
the initiator sees the device as /dev/sda
on the initiator i've created 2 partition /dev/sda1 (swap) and /dev/sda2 (ext4)
I want to be able to create backup on of the ext4 fs, without stopping the initiator!
The solution i came up with involves the snapshot feature of LVM, kpartx from multipath-tools and some backup method (i prefer rdiff-backup or safekeep).
steps:
@qw3r
qw3r / gist:1147971
Created August 15, 2011 21:55 — forked from powmedia/gist:1081802
Backbone.sync for Titanium
//Customise Backbone.sync to work with Titanium rather than jQuery
Backbone.sync = (function() {
var methodMap = {
'create': 'POST',
'read' : 'GET',
'update': 'PUT',
'delete': 'DELETE'
};
var xhr = Ti.Network.createHTTPClient({ timeout: 5000 });
@qw3r
qw3r / gist:1095221
Created July 20, 2011 15:50 — forked from amedeo/gist:820412
CouchDB and multiple tags

CouchDB and multiple tags

The problem

Given a set of documents, each associated with multiple tags, how can I retrieve the documents tagged with an arbitrary set of tags?

My solution

@qw3r
qw3r / my-gh-issues.rb
Created May 8, 2011 10:57 — forked from copiousfreetime/my-gh-issues.rb
My Github Issues
#!/usr/bin/env ruby
#
# A quick script to dump an overview of all the open issues in all my github projects
#
require 'octokit'
require 'awesome_print'
require 'rainbow'
module CouchDBAttachments
def attachment(*args)
lambda do |env|
request = ActionDispatch::Request.new(env)
doc = DocWithAttachments.get(request.params[:doc])
serve_attachment(doc, request.params[:path])
end
end
private
#!/usr/bin/env ruby
#
# Put this script in your PATH and download from onemanga.com like this:
# onemanga_downloader.rb Bleach [chapter number]
#
# You will find the downloaded chapters under $HOME/Documents/OneManga/Bleach
#
# If you run this script without arguments, it will check your local manga downloads
# and check if there are any new chapters
#