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 / otpauth_test_authenticate.py
Created January 9, 2016 01:17
playing with python otpauth
#!/usr/bin/env python
import click
import sys
from datetime import datetime, timedelta
from otpauth import OtpAuth
SECRET = "youHoyahc4Xee7geo6oo"
@click.command()
@cecepm
cecepm / merge.md
Last active December 20, 2015 18:07
Git Merge

Merge feature_branch to master

Pull update on master branch

git checkout master
git pull

Change back to feature_branch, pull and then rebase based on master branch, and resolve conflict (if any)

git checkout feature_branch

@cecepm
cecepm / jenkins.yml
Last active August 29, 2015 14:25
Ansible task for Installing jenkins LTS release on Ubuntu
---
- name: Add Jenkins apt key
apt_key: url=http://pkg.jenkins-ci.org/debian-stable/jenkins-ci.org.key state=present
- name: Add Java repository to sources
apt_repository: repo="deb http://pkg.jenkins-ci.org/debian-stable binary/" state=present
- name: Update APT package cache
apt: update_cache=yes
@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
@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 / 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 / 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: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 / 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 / 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