Skip to content

Instantly share code, notes, and snippets.

View chernjie's full-sized avatar

CJ (curl | jq) chernjie

View GitHub Profile

git-gh-setup


This scripts will find all github remotes in the current repository and add a new configuration that allows you to fetch pull request heads and merge-heads

+refs/pull/*/head
+refs/pull/*/merge

Example:

@chernjie
chernjie / paypal-payout.sh
Last active August 29, 2015 14:22
HackerspaceSG membership payment via PayPal Rest API
#!/usr/bin/env bash
##
# Update your configuration here
# You may get your `client_id` and `client_secret` from developer.paypal.com
# For membership level, please refer to http://hackerspace.sg/membership
##
endpoint=api.paypal.com
client_id=$client_id
#!/usr/bin/env bash
_usage () {
echo Cherry pick merge commits >&2
exit 1
}
_error () {
echo "$@" >&2
exit 1
@chernjie
chernjie / logrotate.d-docker
Created April 17, 2015 17:31
Logrotate docker logs, copy this file to /etc/logrotate.d/docker
/var/lib/docker/containers/*/*-json.log {
dateext
daily
rotate 365
compress
delaycompress
missingok
}
@chernjie
chernjie / 10-magento-filter.conf
Created March 19, 2015 04:59
Logstash multiline filter for Magento
filter {
if [type] == "magento" {
multiline{
pattern => "^%{TIMESTAMP_ISO8601:timestamp}"
what => "previous"
negate=> true
}
grok {
match => [
"message",
#!/usr/bin/env bash
use() {
for i do
if ! command -v $i > /dev/null
then
echo command $i not found
exit 1
fi
done
@chernjie
chernjie / git-gh-setup.sh
Created February 9, 2015 09:25
Fetch Github's Pull Request as a remote branch
#!/usr/bin/env bash
git remote -v | grep fetch | grep github | \
while read remote url _; do
if ! git config --get-all "remote.$remote.fetch" | grep -q refs/pull
then
git config --add "remote.$remote.fetch" \
'+refs/pull/*/head:refs/remotes/'"$remote"'/pull/*'
fi
done
@chernjie
chernjie / git-ps1.source
Last active April 24, 2018 10:34
source git-ps1.source
#!/usr/bin/env bash
# Source git completion and git prompts
command -v __git_ps1 > /dev/null ||
for i in git-completion.bash git-prompt.sh
do
echo source ~/bin/$i
source ~/bin/$i
done
if declare -f __git_ps1 2>&1 >/dev/null
<?php
$handle = fopen($argv[1], 'r');
$handle || exit('no readable file');
$handles = array();
while (($line = fgets($handle)) !== false)
{
if (preg_match('/^201.-..-../', $line, $match))
@chernjie
chernjie / splitLogFileByDate.sh
Last active August 29, 2015 14:03
Split log file by date
#!/bin/bash
function breakup()
{
LAST=$(wc -l "$1" | xargs | cut -d' ' -f1)
LAST=$(($LAST + 1))
grep -no ^201.-..-.. "$1" | sort -u -t: -k2 | sort -t: -rnk1 | while read j
do
DATE=$(echo $j | cut -d: -f2)
LINE=$(echo $j | cut -d: -f1)