Skip to content

Instantly share code, notes, and snippets.

View ctrochalakis's full-sized avatar

Christos Trochalakis ctrochalakis

View GitHub Profile
@technoweenie
technoweenie / gist:2568117
Created May 1, 2012 14:04
Python Master/Worker forking with ZeroMQ instead of unix signals.
# Don't use this.
import zmq
import os
class Worker:
def __init__(self):
print "parent: %d, pid: %d" % (os.getppid(), os.getpid())
self.pid = os.getppid()
self.context = zmq.Context()
self.sub = self.context.socket(zmq.SUB)
@authorNari
authorNari / gc-cow.rb
Created March 24, 2012 00:38 — forked from wr0ngway/gc-cow.rb
test to see if GC in ruby 2 is truly copy on write friendly
#!/usr/bin/env ruby
rss = '.+?Rss:\s+(\d+)'
share = '.+?Shared_Clean:\s+(\d+)'
share << '.+?Shared_Dirty:\s+(\d+)'
priv = '.+?Private_Clean:\s+(\d+)'
priv << '.+?Private_Dirty:\s+(\d+)'
MEM_REGEXP = /\[heap\]#{rss}#{share}#{priv}/m
def mem_usage()

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

@funny-falcon
funny-falcon / performance_and_backport_gc.patch
Created February 18, 2012 12:26
Union of backport GC and performance patches for ruby-1.9.3-p125
diff --git a/Changelog.backport_gc b/Changelog.backport_gc
new file mode 100644
index 0000000..b617fc8
--- /dev/null
+++ b/Changelog.backport_gc
@@ -0,0 +1,128 @@
+Tue Jan 17 12:32:46 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * gc.c (aligned_malloc, aligned_free): covered missing defined
+ operators and fixes for cygwin.
@bierbaum
bierbaum / openssl-1.0.0g-npn.patch
Created February 8, 2012 19:18
OpenSSL 1.0.0g NPN Patch (github.com/jpinner)
diff -rupN openssl-1.0.0g/apps/apps.c openssl-1.0.0g-npn//apps/apps.c
--- openssl-1.0.0g/apps/apps.c 2011-03-19 02:44:25.000000000 -0700
+++ openssl-1.0.0g-npn//apps/apps.c 2012-02-08 11:07:50.667074885 -0800
@@ -2693,6 +2693,48 @@ void jpake_server_auth(BIO *out, BIO *co
#endif
+/* next_protos_parse parses a comma separated list of strings into a string
+ * in a format suitable for passing to SSL_CTX_set_next_protos_advertised.
+ * outlen: (output) set to the length of the resulting buffer on success.
@funny-falcon
funny-falcon / 01_testapp_prepare.sh
Created January 30, 2012 03:28
Testing application for GC
git clone git://github.com/RailsApps/rails3-devise-rspec-cucumber.git rails3app
cd rails3app
#lets increase working set
sed -i 's/, :group.*//' Gemfile
sed -i '/^\(group\|end\)/ d' Gemfile
rm Gemfile.lock
bundle install
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rails runner '(1..20).each{|i| User.create(email: "as#{i}@df.gh", name: "asdf#{i}", password: "asdfghjk")}'
bundle exec rake assets:precompile
@jc00ke
jc00ke / capybara-helpers.rb
Created January 28, 2012 07:47
Capybara helpers
def screenshot
require 'capybara/util/save_and_open_page'
now = Time.now
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}"
Capybara.save_page body, "#{p}.html"
path = Rails.root.join("#{Capybara.save_and_open_page_path}" "#{p}.png").to_s
page.driver.render path
Launchy.open path
end
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@dgutov
dgutov / gist:1274520
Created October 10, 2011 02:35
ruby-indent-line advice for closing paren
(defadvice ruby-indent-line (after unindent-closing-paren activate)
(let ((column (current-column))
indent offset)
(save-excursion
(back-to-indentation)
(let ((state (syntax-ppss)))
(setq offset (- column (current-column)))
(when (and (eq (char-after) ?\))
(not (zerop (car state))))
(goto-char (cadr state))
@addyosmani
addyosmani / codereview.md
Created August 25, 2011 12:11
Lessons from a JavaScript code review

#Lessons From A JavaScript Code Review

I was recently asked to review some code for a new JavaScript application and thought I might share some of the feedback I provided as it includes a mention of JavaScript fundamentals that are always useful to bear in mind. Code reviews are possibly the single biggest thing you can do to improve the overall quality of your solutions and if you're not actively taking advantage of them, you're possibly missing out on bugs you haven't noticed being found or suggestions for improvements that could make your code better.

##Challenges & Solutions

Code reviews go hand-in-hand with maintaining strong coding standards. That said, standards don't usually prevent logical errors or misunderstandings about the quirks of a programming language. Even the most experienced developers can make these kinds of mistakes and code reviews can greatly assist with catching them.

Often the most challenging part of code reviews is actually finding an experienced developer you trust to complete