Skip to content

Instantly share code, notes, and snippets.

@marvin
marvin / gist:977346
Created May 17, 2011 20:42
integrate image to rails link_to - requires jquery-ui. the code creates 3 icons for show,edit and destroy
<%= link_to content_tag(:span, '', :class => "ui-icon ui-icon-folder-open"), yourname, :title => "Show", :class => "ui-state-default ui-corner-all", :id => "no-border" %>
<%= link_to content_tag(:span, '', :class => "ui-icon ui-icon-gear"), edit_yourname_path(yourname), :title => "Edit", :class => "ui-state-default ui-corner-all", :id => "no-border" %>
<%= link_to content_tag(:span, '', :class => "ui-icon ui-icon-trash"), yourname, :confirm => "Are you sure you?", :title => "Delete", :method => :delete, :class => "ui-state-default ui-corner-all", :id => "no-border" %>
@marvin
marvin / truncate_words_helper.rb
Created June 7, 2011 22:03
helper to truncate words
def truncate_words(text, length, end_string = ' ...')
words = text.split()
words = words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
end
@marvin
marvin / gist:1017389
Created June 9, 2011 18:27
ruby regular expression validate http, email, ip, netmask, ip in range
validate email: /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
validate url: ^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
validate ip: /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i
validate ip ranges: /^\b(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]?)\b$/i
validate netmask: /^(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$/i
@marvin
marvin / gist:1017480
Created June 9, 2011 19:16
syslog calculate facility and severity from PRI(priority)
example:
PRI = 191
To get the Facility
Divide the PRI number by 8.
191/8 = 23.875
The whole number part is the facility.
To get the Severity
@marvin
marvin / gist:1075455
Created July 11, 2011 07:58
ruby to_sentence configurations
>> %w(lorem ipsum dolor sit).to_sentence
=> "lorem, ipsum, dolor, and sit"
>> %w(lorem ipsum dolor sit).to_sentence(:words_connector => ' + ')
=> "lorem + ipsum + dolor, and sit"
>> %w(lorem ipsum).to_sentence(:two_words_connector => ' through ')
=> "lorem through ipsum"
# No effect if more than two words
@marvin
marvin / gist:1375897
Created November 18, 2011 08:24
edit dialog
// new account form
$(function() {
$('.account-edit-dialog-form').dialog({ autoOpen: false })
$( ".account-edit-dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 500,
modal: true,
@marvin
marvin / Gemfile
Created January 20, 2012 12:59
DataMapper repository issues
source "http://rubygems.org"
gem 'sinatra', '~> 1.3.2', :require => 'sinatra'
gem 'data_mapper', '~> 1.2.0'
gem 'dm-mongo-adapter', :git => 'https://github.com/solnic/dm-mongo-adapter.git', :branch => "dm-1.2-compatible"
gem 'bson_ext', '~> 1.4.0'
gem 'mongo', '~> 1.4.0'
gem 'mongodb', '~> 2.0.0'
gem 'dm-sqlite-adapter'
gem 'haml'
@marvin
marvin / camscan.py
Created February 7, 2012 20:39
scans for netcam exploidable cameras. requires shodan lib and API Key
from shodan import WebAPI
import re,socket
key = 'YOURKEYHERE'
filter = 'netcam'
def checkCam(ip):
try:
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.settimeout(1.5)
@marvin
marvin / guestbook-vulnerable.php
Created February 15, 2012 15:16
php CSRF attack guestbook
<?php
$sDataFile = 'guestbook.dat';
$sLogFile = 'adminlog.dat';
touch($sDataFile);
touch($sLogFile);
if (isset($_GET['logfile'])) show_logfile($sLogFile);
@marvin
marvin / 1kbforum.php
Created February 16, 2012 12:23
1kb forum
<html><body><h1>1KB Forum</h1><?mysql_connect('localhost','username','********');mysql_select_db('d');extract($_REQUEST);$v=intval($v);$i=0;$q='mysql_query';$f='mysql_fetch_row';$n='mysql_num_rows';$x='<input type="';$s="SELECT*FROM";$t='CREATE TABLE IF NOT EXISTS t(i INT AUTO_INCREMENT,a INT,b TEXT,KEY(i))';$h='htmlspecialchars';$q($t);$q(str_replace('t','p',$t));$l=' ORDER BY';$o='';$u='INSERT INTO';$c="b)VALUES('";if($b){if(!$v)$q("$u t($c$e')");$v=max($v,mysql_insert_id());$q("$u p(a,$c$v','$b')");}if($v){$t=$q("$s p WHERE a=$v$l i");echo'<a href="f.php">Back</a>';for(;$i<$n($t);++$i){$r=$f($t);echo'<hr/>'.nl2br($h($r[2]));}}else{$t=$q("$s t$l-i");for(;$i<$n($t);++$i){$r=$f($t);echo'<a href="f.php?v='.$r[0].'">'.$h($r[2]).'</a><br/>';}$o='Title:'.$x.'text"name="e"/><br/>';}echo'<hr/>Post:<form action="f.php"method="post">'.$x.'hidden"name="v"value="'."$v\"/>$o<textarea name=\"b\"></textarea>$x";?>submit"name="w"value="Post"/></form></body></html>