Skip to content

Instantly share code, notes, and snippets.

View CyberLight's full-sized avatar
🎓
in training

Aleksandr Vishniakov CyberLight

🎓
in training
View GitHub Profile
Warden::Strategies.add(:bcrypt) do
def valid?
params[:username] || params[:password]
end
def authenticate!
return fail! unless user = User.first(:username => params[:username])
if user.encrypted_password == params[:password]
success!(user)
@gruber
gruber / Liberal Regex Pattern for All URLs
Last active March 28, 2025 11:25
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:[email protected]", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
@eligrey
eligrey / object-watch.js
Created April 30, 2010 01:38
object.watch polyfill in ES5
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
Rails.configuration.middleware.use Rack::OpenID
Rails.configuration.middleware.use RailsWarden::Manager do |manager|
manager.default_strategies :remember_me_token, :password_form, :api_token, :openid
manager.failure_app = ExceptionsController
end
# Setup Session Serialization
class Warden::SessionSerializer
def serialize(record)
@bindle
bindle / test-dlsym.c
Created November 4, 2010 20:32
simple example of dlsym()
/*
* Quick example to test dlsym()
* build: gcc -W -Wall -Werror -o test-dlsym test-dlsym.c
* Usage: ./test-dlsym openldap
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
anonymous
anonymous / gist:985918
Created May 22, 2011 21:33
function IntervalMonitor() {
var intervals = [];
this.start = function (callback, repeat) {
var res = setInterval(callback, repeat);
intervals.push(res);
return res;
};
this.stop = function (item) {
@pixelhandler
pixelhandler / hijack_form_submit.js
Created July 14, 2011 04:10
Hijack form’s submit onclick, validate, and use enter key to post form
// using jQuery library and validation plugin in this code
// for checking keycodes
function getKeyCode(event) {
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
return keycode;
}
// is there an anchor as Submit button?
var $submit = $('a[id$="_submit"]');
// is there any behavior already on submit, like -> onclick="__doPostBack(...)"
@mxcl
mxcl / uninstall_homebrew.sh
Created August 26, 2011 11:25
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@cordoval
cordoval / bdd-experiment-guide.md
Created September 9, 2011 16:38 — forked from havvg/bdd-experiment-guide.md
Behavior Driven Development in Symfony2 with Behat, Mink and Zombie.js

Description

This guide will show how to setup a new web application project with:

  • git, a distributed version control system.
  • Symfony2 framework
  • Behat, a tool for behavior driven development.
  • Mink, a tool unifying access to browser emulators wrapping them into one API.
  • Zombie.js, a browser emulator.
  • PHPUnit, the de-facto standard test suite in the PHP world.
@cyberdelia
cyberdelia / mixin.py
Created September 21, 2011 08:26
Django class based view mixins
# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import login_required
from django.utils.cache import patch_response_headers
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page, never_cache
from django.views.decorators.csrf import csrf_exempt
class NeverCacheMixin(object):
@method_decorator(never_cache)