Skip to content

Instantly share code, notes, and snippets.

@yevrah
yevrah / token_sort.sh
Last active August 29, 2015 14:08
Sort classes, methods or other tokens in a file
#!/bin/sh
# sort on perl subs, can be changed to any other token for any other language
TOKEN=sub
gsed -e ':a;N;$!ba;s/\n/__newline__/g' "$1" > "$1.out"
gsed -i "s/__newline__\\s*$TOKEN\W/\\nsub /g" "$1.out"
sort $1.out -o $1.out
gsed -i 's/__newline__/\n/g' $1.out
@yevrah
yevrah / parse_log_date.pl
Last active August 29, 2015 14:07
Logfile Date Filtering
#!/usr/bin/env perl
use strict 'vars';
use feature qw/say/;
my $date_from = &date_to_int( 'Oct', '14', '20', '00', '00');
my $date_to = &date_to_int( 'Oct', '15', '21', '00', '00');
while ( <DATA> ) {
chomp;
my ($month, $day, $hour, $min, $sec, $server, $msg) = $_ =~ m/(\w+) (\d+) (\d+):(\d+):(\d+) (\w+) (.*)/;
@yevrah
yevrah / distances.py
Created October 14, 2014 01:03
Python using free map tools to calculate distance as the crows fly
import requests
import math
from BeautifulSoup import BeautifulSoup
def distance_on_unit_sphere(lat1, long1, lat2, long2):
"src: http://www.johndcook.com/python_longitude_latitude.html"
degrees_to_radians = math.pi/180.0
phi1 = (90.0 - lat1)*degrees_to_radians
phi2 = (90.0 - lat2)*degrees_to_radians
@yevrah
yevrah / new_file0
Last active August 29, 2015 14:06
MySQL: Load data fast!
# More information can be found;
# - http://dev.mysql.com/doc/refman/5.1/en/load-data.html
# - http://dev.mysql.com/doc/refman/5.5/en/optimizing-innodb-bulk-data-loading.html
SET autocommit=0;SET unique_checks=0;SET foreign_key_checks=0;
LOAD DATA INFILE IGNORE 'my_data.csv' INTO TABLE my_table
COMMIT;SET unique_checks=1;SET foreign_key_checks=1;
@yevrah
yevrah / new_file0
Created September 17, 2014 23:02
Generate sqlAlchemy classes from existing db
pip install sqlacodegen
pip install MySQL-python
sqlacodegen mysql://www:www@localhost/db_name
@yevrah
yevrah / copy_ssh_keys.sh
Created September 2, 2014 22:11
Copy SSH Keys To Remote Server
#!/usr/bin/env bash
# Usage
# copy_ssh_keys.sh user@host
#
# Notes
# Makes sure to generate your ssh keys before running, if
# you havent done so just uncomment the line below
# ssh-keygen -t rsa
echo -e "\n>>> Creating remote .ssh folder"
@yevrah
yevrah / print_same.py
Created September 2, 2014 22:11
Printing on the same line
#!/usr/bin/env python
# encoding: utf-8
# This is an example of how to print a console
# message on the same line
from time import sleep
import sys
def ps(string):
@yevrah
yevrah / print_same.py
Created September 2, 2014 22:11
Printing on the same line
#!/usr/bin/env python
# encoding: utf-8
# This is an example of how to print a console
# message on the same line
from time import sleep
import sys
def ps(string):
@yevrah
yevrah / print_same.py
Created September 2, 2014 22:11
Printing on the same line
#!/usr/bin/env python
# encoding: utf-8
# This is an example of how to print a console
# message on the same line
from time import sleep
import sys
def ps(string):
@yevrah
yevrah / print_same.py
Created September 2, 2014 22:11
Printing on the same line
#!/usr/bin/env python
# encoding: utf-8
# This is an example of how to print a console
# message on the same line
from time import sleep
import sys
def ps(string):