Skip to content

Instantly share code, notes, and snippets.

View arsham's full-sized avatar

Arsham Shirvani arsham

View GitHub Profile
@arsham
arsham / innerFiller.sql
Created May 17, 2013 15:50
Update a table, feeding a column from inner join of two other tables as reference
UPDATE T1P
INNER JOIN T2
ON T1.match1 = T2.match1
INNER JOIN T3
ON T3.match2 = T2.match2
SET T1.new_column = T3.source_of_new_column;
@arsham
arsham / mysql.sublime-build
Last active January 25, 2016 08:53
Sublime Text 2/3 mysql build system. Change USERNAME, PASSWORD, DATABASE and the output file to your needs. Note: on cmd line, change "subl3" to proper application name.
{
"cmd": ["mysql -u USERNAME -pPASSWORD DATABASE -t < $file >> /tmp/output.sql ; subl3 /tmp/output.sql"],
"selector": "source.sql",
"shell" : true
}
@arsham
arsham / TwoSpacesToFourIndention.sublime-macro
Created January 7, 2015 11:52
A Sublime Text Macro to convert 2 spaces indentions to 4
[
{
"args": null,
"command": "select_all"
},
{
"args": {
"setting": "tab_size",
"value": 2
},
@arsham
arsham / md5dir
Created January 12, 2015 10:30
Returns the md5sum of the folder. It's recursive
#!/bin/bash
find $1/ -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum
@arsham
arsham / install_package_in_env_env
Last active August 29, 2015 14:14
Installing external package in virtualenv for edit purposes
# Do this in your environment
python setup.py develop --install-dir /path/to/virtualen/lib/python3.4/site-packages
# or: python setup.py develop --multi-version --exclude-scripts --install-dir /path/to/virtualen/lib/python3.4/site-packages
@arsham
arsham / database_size
Last active August 29, 2015 14:14 — forked from cmlenz/gist:1992369
-- PostgreSql
SELECT
pg_database.datname AS "Database Name",
pg_database_size(pg_database.datname) / 1024.0 / 1024.0 AS "Database Size (MB)"
FROM pg_database;
-- MySql
SELECT
table_schema "Database Name",
sum( data_length + index_length ) / 1024 / 1024 "Database Size (MB)"
//This function was used in my test rig to convert elasticsearch results to a KML structure which is
// later fed to an iFrame wrapping the GoogleEarth plugin
var data=[];
var buckets=inData.aggregations.map.buckets;
function addCommas(nStr)
{
nStr += '';
@arsham
arsham / update_auto_val
Created March 6, 2015 09:09
Updates the incremental value of the PK.
SELECT setval('TEABLE_NAME_id_seq', (SELECT MAX(id) FROM TEABLE_NAME));
@arsham
arsham / python_email_debugger
Created March 6, 2015 09:14
Python SMTP debugger in shell
#!/bin/bash
python -m smtpd -n -c DebuggingServer localhost:1025
@arsham
arsham / request_generator.py
Created March 6, 2015 17:16
Creates a django request object for test purposes
from django.test.client import RequestFactory
factory = RequestFactory()
request = factory.get('/')