Skip to content

Instantly share code, notes, and snippets.

View guerrerocarlos's full-sized avatar
:octocat:
On shoulders of giants.

Carlos Guerrero guerrerocarlos

:octocat:
On shoulders of giants.
View GitHub Profile
@guerrerocarlos
guerrerocarlos / get_app_data.js
Created August 24, 2012 20:30
get_app_data function of OpenERP
get_app_data: function() {
var self = this;
return $.when(
new db.web.Model("res.users").get_func("read")(this.session.uid, ['shop_id']).pipe(function(result) {
var shop_id = result['shop_id'][0];
new db.web.Model("sale.shop").get_func("search_read")([['id','=',shop_id]],[]).pipe(function(result) {
self.set({'shop': result[0]});
var company_id = result[0]['company_id'][0];
return new db.web.Model("res.company").get_func("read")(company_id, ['currency_id', 'name', 'phone']).pipe(function(result) {
@guerrerocarlos
guerrerocarlos / main.js
Created September 6, 2012 05:07
loading socket.io using require.js
// Require.js allows us to configure shortcut alias
require.config({
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
'socketio': {
exports: 'io'
},
'underscore': {
exports: '_'
@guerrerocarlos
guerrerocarlos / .bashrc
Created October 30, 2012 00:07
extract
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
@guerrerocarlos
guerrerocarlos / middleware.py
Created October 31, 2012 22:47 — forked from strogonoff/middleware.py
Django middleware for cross-domain XHR
from django import http
try:
from django.conf import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
XS_SHARING_ALLOWED_METHODS = settings.XS_SHARING_ALLOWED_METHODS
XS_SHARING_ALLOWED_HEADERS = settings.XS_SHARING_ALLOWED_HEADERS
XS_SHARING_ALLOWED_CREDENTIALS = settings.XS_SHARING_ALLOWED_CREDENTIALS
except AttributeError:
XS_SHARING_ALLOWED_ORIGINS = '*'
@guerrerocarlos
guerrerocarlos / requirements.txt
Created November 8, 2012 16:45
Librerias de python necesarias para OpenERP 6.1
babel>=0.9.6
cherrypy==3.1.2
formencode>=1.2.4
mako>=0.4.1
#pychart>=1.39
pyyaml>=3.09
egenix-mx-base>=3.2.0
lxml>=2.3
psycopg2>=2.4
pydot>=1.0.25
@guerrerocarlos
guerrerocarlos / paypal.py
Created November 9, 2012 20:43
Paypal payment checking function
import urllib
import urllib2
def paypal_check(tx,at):
success = False
post_data = [('cmd','_notify-synch'),('tx',tx),('at',at)] # a sequence of two element tuples
result = urllib2.urlopen('https://www.paypal.com/cgi-bin/webscr', urllib.urlencode(post_data))
content = result.read().split('\n')
results = {}
@guerrerocarlos
guerrerocarlos / ffmpeg
Created November 16, 2012 02:07
ffmpeg commands for iphone-compatible output
#Faster Low Quality result in mp4
ffmpeg -i Before.Sunrise.DVDRip.XviD-SChiZO.avi -acodec libfaac -ab 128k -ar 44100 -vcodec mpeg4 -b 1000K -s 640x480 destination.m4v
#Better Quality result in mp4
ffmpeg -i input.avi -f mp4 -y -vcodec libxvid -maxrate 1000k -mbd 2 -qmin 3 -qmax 5 -g 300 -bf 0 -acodec libfaac -ac 2 -flags +mv4 -trellis 2 -cmp 2 -subcmp 2 salida.mp4
@guerrerocarlos
guerrerocarlos / generate-netfilter-u32-dns-rule.py
Created March 4, 2013 02:40
DNS Amplification DDOS ". ANY" attack can be stopped by using this iptable: iptables -A INPUT -p udp --dport 53 -m u32 --u32 $(python generate-netfilter-u32-dns-rule.py --qname . --qtype ANY) -j DROP
#!/usr/bin/python
"""
Produces a Linux Netfilter u32 rule to match DNS requests for a given
domain name and/or a given query type.
Typical usage:
% python generate-netfilter-u32-rule.py --qname ripe.net --qtype ANY
Can be embedded in iptables' invocations for instance:
rule=$(python generate-rule.py args...)
@guerrerocarlos
guerrerocarlos / block_ddos
Last active January 11, 2021 19:05
Blocking all ANY queries in DNS server to prevent DDOS DNS amplification attack
iptables --flush
iptables -A INPUT -p udp --dport 53 -m string --from 50 --algo bm --hex-string '|0000FF0001|' -m recent --set --name dnsanyquery
iptables -A INPUT -p udp --dport 53 -m string --from 50 --algo bm --hex-string '|0000FF0001|' -m recent --name dnsanyquery --rcheck --seconds 60 --hitcount 1 -j DROP
iptables -A INPUT -p udp --dport 53 -m u32 --u32 $(python generate-netfilter-u32-dns-rule.py --qname . --qtype ANY) -j DROP
#iptables -A INPUT -p udp --dport 53 -m u32 --u32 $(python generate-netfilter-u32-dns-rule.py --qname isc.org --qtype ANY) -j DROP
#iptables -A INPUT -p udp --dport 53 -m u32 --u32 $(python generate-netfilter-u32-dns-rule.py --qname isc.org. --qtype ANY) -j DROP
iptables -A INPUT -p udp --dport 53 -m string --from 50 --algo bm --hex-string '|0000FF0001|' -j DROP
#para bloquear ataque isc.org
iptables -A INPUT -p udp -m string --hex-string "|03697363036f726700|" --algo bm --to 65535 -j DROP
public void mostrarToast(View view,String msj){
Context context = view.getContext();
CharSequence text = msj;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}