Skip to content

Instantly share code, notes, and snippets.

View maxp's full-sized avatar

Maxim Penzin maxp

View GitHub Profile
@maxp
maxp / ddos-filter.sh
Created January 11, 2012 06:17
ddos filter
tcpdump -v -n -w attack.log dst port 80 -c 250
tcpdump -nr attack.log |awk '{print $3}' \
|grep -oE '[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}' |sort |uniq -c |sort -rn |head -20
#!/bin/bash
BLOCKDB="ips.txt"
IPS=$(grep -Ev "^#" $BLOCKDB)
for i in $IPS
@maxp
maxp / html_render.coffee
Created November 22, 2011 03:36
Coffeescript html_renderer
tag = (name, content, attributes) ->
name: name
attributes: attributes
content: content
htmlDoc = (title, bodyContent) ->
tag "html", [tag("head", [tag "title", [title]]),
tag "body", bodyContent]
@maxp
maxp / script-insert.js
Created November 19, 2011 04:48
fast insert script tag
(function(){
var e = document.createElement('script'); e.type='text/javascript';
e.async = true;
e.src = document.location.protocol + '//yourdomain.com/packaged_third_party_javascript.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(e, s);
})();
@maxp
maxp / topic_unread.sql
Created November 4, 2011 08:33
forum unread topic
create table user ( id serial, ... );
create table group ( id serial, ... );
create table topic (
id serial,
group_id int foreign key group(id)
);
create table lastread (
id serial,
@maxp
maxp / NMEA_checksum
Created September 4, 2011 17:44
Calculating an NMEA Checksum (C#)
// Calculates the checksum for a sentence
// Calculates the checksum for a sentence
static string getChecksum(string sentence) {
//Start with first Item
int checksum= Convert.ToByte(sentence[sentence.IndexOf('$')+1]);
// Loop through all chars to get a checksum
for (int i=sentence.IndexOf('$')+2 ; i<sentence.IndexOf('*') ; i++){
// No. XOR the checksum with this character's value
checksum^=Convert.ToByte(sentence[i]);
@maxp
maxp / send_email.py
Created August 7, 2011 13:51
how to make correct smtp headers
from smtplib import SMTP
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import parseaddr, formataddr
def send_email(sender, recipient, subject, body):
"""Send an email.
All arguments should be Unicode strings (plain ASCII works as well).
<meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE" />
If you do, then ONLY phone numbers within the following tags will be highlighted:
<!-- sphoneid telnr="+15551234456" fileas="John Smith" -->(555) 1234 456<!-- sphoneid -->
http://forum.skype.com/index.php?showtopic=78380
@maxp
maxp / pi.c
Created April 7, 2011 15:09
Program to compute an approximation of pi by Brian Westley, 1988
// required: gcc -traditional-cpp pi.c
#define _ -F<00||--F-OO--;
int F=00,OO=00;
main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
{
_-_-_-_
_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
@maxp
maxp / vim-russian.vim
Created March 26, 2011 14:37
vim russian
set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
highlight lCursor guifg=NONE guibg=Cyan
:setlocal spell spelllang=ru_yo,en_us
:setlocal spell spelllang=ru_ru,en_us
# use Ctrl-^ to switch
class AttrDict(dict):
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, value)
self[key] = value