Skip to content

Instantly share code, notes, and snippets.

View cecepm's full-sized avatar

Cecep Mahbub cecepm

  • Jakarta, Indonesia
View GitHub Profile
@cecepm
cecepm / Anaconda.sublime-settings
Last active December 31, 2015 11:59
My SublimeText Settings
{
"anaconda_linting_behaviour": "save-only",
"pep8_ignore":
[
"E501",
"E501",
"E701",
"E126",
"E127",
"E128",
@cecepm
cecepm / create_template_postgis-debian.sh
Last active December 31, 2015 22:09
Create PostGIS Template in Ubuntu 12.04
#!/bin/bash
#
# Taken and modified from
# https://docs.djangoproject.com/en/dev/_downloads/create_template_postgis-debian.sh
GEOGRAPHY=0
POSTGIS_SQL=postgis.sql
# For Ubuntu 12.04 (with PostGIS 1.5)
if [ -d "/usr/share/postgresql/9.1/contrib/postgis-1.5" ]
@cecepm
cecepm / argparse_sample1.py
Created January 2, 2014 10:20
argparse simple case, required input file, but optional output file
#!/usr/bin/env python
# encoding: utf-8
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('infile', type=argparse.FileType('r'), help='Input file in CSV format.')
parser.add_argument('-o', '--outfile', type=argparse.FileType('wb'), help='Output file in CSV format.')
args = parser.parse_args()
@cecepm
cecepm / ipython_notebook_config.py
Last active January 2, 2016 19:09
Run Django Shell using IPython Notebook

Tested with iPython 2.0, Django 1.6

Install

Install Django Extension

pip install django-extensions

Install IPython

@cecepm
cecepm / gist:8913718
Last active August 29, 2015 13:56
Sed change from href="{{ MEDIA_URL }}css/default.css" to href="{% static "css/default.css" %}"
sed -e 's/href=\"{{ MEDIA_URL }}\([^"]*\)/href="{% static \"\1\" %}/g'

Explanation

  • Syntax sed -e 's/ find / replace /'
  • href=\"{{ MEDIA_URL }} --> match href="{{ MEDIA_URL }}
  • \([^"]*\) --> match any chars before " and save on variable \1
@cecepm
cecepm / gist:9799597
Last active August 29, 2015 13:57
Install Cacti on Ubuntu 14.04

Install Nginx

sudo apt-get install nginx

Install MySQL, rrdtool, snmp

sudo apt-get install mysql-server rrdtool snmp snmpd

Install PHP-FPM and PHP modules

@cecepm
cecepm / round.sql
Created December 23, 2014 04:51
PostgreSQL: round time function
CREATE OR REPLACE FUNCTION round_minutes( TIMESTAMP WITH TIME ZONE, integer)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
SELECT date_trunc('hour', $1) + (cast(($2::varchar||' min') as interval) * round( (date_part('minute',$1)::float + date_part('second',$1)/ 60.)::float / cast($2 as float)))
$$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION floor_minutes( TIMESTAMP WITH TIME ZONE, integer )
RETURNS TIMESTAMP WITH TIME ZONE AS $$
SELECT round_minutes( $1 - cast((($2/2)::varchar ||' min') as interval ), $2 );
$$ LANGUAGE SQL IMMUTABLE;
@cecepm
cecepm / gist:1589ecb2332ff7ec7ac9
Created April 23, 2015 03:11
tcpdump sniff mysql
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}'
@cecepm
cecepm / get_jdk.sh
Created June 26, 2015 01:57
Download java JDK using wget
wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz" \
-O jdk-7u79-linux-x64.tar.gz
## if you need java cryptography extension
#wget --no-cookies \
# --no-check-certificate \
# --header "Cookie: oraclelicense=accept-securebackup-cookie" \
@cecepm
cecepm / java.yml
Last active August 23, 2018 02:52
Ansible playbook for installing java from Webupd8team PPA.
---
- name: ensure required packages are installed for Java 7
apt: name={{ item }} state=latest update_cache=yes
with_items:
- python-software-properties
- name: Add Java repository to sources
apt_repository: repo='ppa:webupd8team/java'
- name: Autoaccept license for Java