Skip to content

Instantly share code, notes, and snippets.

View FooBarWidget's full-sized avatar

Hongli Lai FooBarWidget

View GitHub Profile
# Returns the RVM installation mode:
# :single - RVM is installed in single-user mode.
# :multi - RVM is installed in multi-user mode.
# :mixed - RVM is in a mixed-mode installation.
# nil - The current Ruby interpreter is not using RVM.
def self.rvm_installation_mode
if in_rvm?
if ENV['rvm_path'] =~ /\.rvm/
return :single
else
@FooBarWidget
FooBarWidget / errortest.py
Created February 1, 2013 21:47
Run ./errortest.py, then run another ./errortest.py while the first one is still running. The second one *should* exit with an error, but instead it gets stuck in the event loop.
#!/usr/bin/env python
import sys
# This is just for me. Comment this out if you want.
sys.path.insert(0, 'Twisted-12.2.0')
sys.path.insert(0, 'zope.interface-4.0.1')
import logging
from twisted.internet import reactor, protocol
from twisted.internet.endpoints import TCP4ServerEndpoint
@FooBarWidget
FooBarWidget / test.c
Last active December 11, 2015 01:29
Compile and run with: gcc -Wall test.c -o test && ./test
/*
Compile and run with: gcc -Wall test.c -o test && ./test
*/
#include <sys/param.h>
#include <unistd.h>
#include <stdio.h>
int
main() {
printf("NGROUPS_MAX = %d\n", NGROUPS_MAX);
alias ls='ls -GFh'
alias dir='ls -l'
alias df='df -h'
alias du='du -h'
alias ri='ri -f ansi'
alias irb='irb --simple-prompt'
alias top='top -o cpu'
alias less='less -R'
export EDITOR=pico
export PAGER=less-r
@FooBarWidget
FooBarWidget / gist:4133511
Created November 23, 2012 01:00
Ruby deployment overview, 2010

(Originally from http://stackoverflow.com/questions/4113299/ruby-on-rails-server-options/4113570#4113570)

The word "deployment" can have two meanings depending on the context. You are also confusing the roles of Apache/Nginx with the roles of other components.

Apache vs Nginx

They're both web servers. They can serve static files but - with the right modules - can also serve dynamic web apps e.g. those written in PHP. Apache is more popular and has more features, Nginx is smaller and faster and has less features.

Neither Apache nor Nginx can serve Rails apps out-of-the-box. To do that you need to use Apache/Nginx in combination with some kind of add-on, described later.

Apache and Nginx can also act as reverse proxies, meaning that they can take an incoming HTTP request and forward it to another server which also speaks HTTP. When that server responds with an HTTP response, Apache/Nginx will forward the response back to the client. You will learn later why this is relevant.

  • Use 4-space tabs for indentation.

  • Wrap at approximately 80 characters. This is a recommendation, not a hard guideline. You can exceed it if you think it makes things more readable, but try to minimize it.

  • Use camelCasing for function names, variables, class/struct members and parameters:

     void frobnicate();
     void deleteFile(const char *filename, bool syncHardDisk);
     int fooBar;
    
diff --git a/ext/common/ApplicationPool2/Pool.h b/ext/common/ApplicationPool2/Pool.h
index e5cd3a8..82ca754 100644
--- a/ext/common/ApplicationPool2/Pool.h
+++ b/ext/common/ApplicationPool2/Pool.h
@@ -482,6 +482,14 @@ public:
typedef shared_ptr<ProcessAnalyticsLogEntry> ProcessAnalyticsLogEntryPtr;
void collectAnalytics(ev::timer &timer, int revents) {
+ try {
+ realCollectAnalytics(timer);
app = proc do |env|
# This is a Ruby C extension method that we've written to simulate a freeze.
# It sleeps indefinitely, and unlike Kernel#sleep it does not unlock the Ruby
# 1.9 interpreter's GIL, so it really freezes everything.
PhusionPassenger::NativeSupport.freeze_process
[200,
{ "Content-Type" => "text/html" },
["hello world\n"]
]
$ crash-watch --dump 5120
Current thread (1) backtrace:
#0 0x00007fff89d2de42 in __semwait_signal ()
No symbol table info available.
#1 0x00007fff8329fdea in nanosleep ()
No symbol table info available.
#2 0x00007fff8329fbb5 in usleep ()
No symbol table info available.
#3 0x00000001001d889a in freeze_process (self=2307) at passenger_native_support.c:468
No locals.

Our live IRB and debugging console provide easy ways to introspect, to debug and to modify your application during runtime.

Ever wondered what your application is doing? Maybe the state is not obvious from the log files or the status screens, and you want to inspect the program state directly. Phusion Passenger Enterprise can help you, so let's see how it works.

So here you have a hello world application, which just prints a message with a counter value. On every request, the counter is increment by 1. And here you see it in action.

We use the passenger-status tool to find the PID our application, which we then pass to the passenger-irb command. And there we go. Let's introspect and change the value of the $processed global variable. And it works, it's this simple.