Skip to content

Instantly share code, notes, and snippets.

View alessioalex's full-sized avatar

Alexandru Vlăduţu alessioalex

View GitHub Profile
class Person < ActiveRecord::Base
before_save :cleanup
def name
"#{first_name} #{last_name}"
end
private
@alessioalex
alessioalex / mail.rb
Created August 8, 2011 19:44 — forked from vivien/mail.rb
Sample script for the mail gem.
#!/usr/bin/env ruby
require "mail"
require "optparse"
imap_opts = {
:address => "imap.gmail.com",
:port => 993,
:enable_ssl => true
}
@alessioalex
alessioalex / gist:1168635
Created August 24, 2011 17:38
JRuby installer failed
alessio@alessio-Extensa-5510:~
→ rvm install jruby
jruby-1.6.3 - #fetching
jruby-1.6.3 - #extracted to /home/alessio/.rvm/src/jruby-1.6.3 (already extracted)
Building Nailgun
jruby-1.6.3 - #installing to /home/alessio/.rvm/rubies/jruby-1.6.3
jruby-1.6.3 - #importing default gemsets (/home/alessio/.rvm/gemsets/)
Copying across included gems
Building native extensions. This could take a while...
ERROR: Error installing jruby-launcher:
@alessioalex
alessioalex / routes.js
Created October 15, 2011 15:01 — forked from tj/routes.js
Express routes
var app = require('../app');
console.log();
app.routes.all().forEach(function(route){
console.log(' \033[90m%s \033[36m%s\033[0m', route.method.toUpperCase(), route.path);
});
console.log();
process.exit();
@alessioalex
alessioalex / gist:1324312
Created October 29, 2011 10:22
bubersson3 - express route
app.get('/lect1.html', function (req, res) {
var a_local_variable;
// you do some stuff here
if (some_condition) {
a_local_variable = value;
}
res.render('lect1', {
// this has a dynamic value
'my_var': a_local_variable
});
@alessioalex
alessioalex / command.sh
Created October 29, 2011 19:42 — forked from felixge/command.sh
Bash stuff for fighting a weak DOS attack
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me:
@alessioalex
alessioalex / gist:1334904
Created November 2, 2011 21:01
Emit event with Mongoose
UserSchema.post('save', function() {
this.emit('changed', this, this.altered);
delete this.altered;
});
@alessioalex
alessioalex / gist:1339202
Created November 4, 2011 12:11
PHP get real IP
function get_real_ip()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
@alessioalex
alessioalex / gist:1342754
Created November 6, 2011 11:07
Winston..
var express = require("express"),
csrf = require('express-csrf'),
form = require('connect-form'),
connectTimeout = require('connect-timeout'),
RedisStore = require('connect-redis')(express),
SessionStore = new RedisStore(),
mongoose = require("mongoose"),
winston = require('winston'),
configs = require("./configs"),
port = process.argv[2] || 80,