Skip to content

Instantly share code, notes, and snippets.

@landys
landys / onchange.sh
Last active July 27, 2016 10:53 — forked from senko/onchange.sh
Watch current directory and execute a command/mutiple commands if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do echo "$line";grep "$line" content.txt; done < filter_words_content.txt
@landys
landys / nginx_switch.sh
Created January 25, 2016 14:27
Snippet of nginx switch
# $1 - tomcat port, $2 - tomcat folder to be replaced, $3 - tomcat folder replace with.
nginx_disable_tomcat()
{
ssh -t bmb@$SERVER "cd $REMOTE_NGINX_DIR; git checkout baomingba.conf; "\
"sed -i -E 's/(server\s127.0.0.1:$1)/#\1/' baomingba.conf; "\
"sed -i -E 's/$2/$3/g' baomingba.conf; "\
"echo $PWD | sudo -S nginx -t && sudo service nginx reload"
check_error "Error: disconnect nginx to tomcat with port $1."
}
@landys
landys / pre-receive-checkstyle-hook.py
Created November 30, 2015 13:38
The git pre-receive hook for java checkstyle check based on http://bluec0re.blogspot.com/2012/05/git-pre-receive-hook-with-checkstyle.html. Set checkstyle jar and xml with "git config checkstyle.checkfile google_checks.xml" and "git config checkstyle.jar checkstyle-6.12.1-all.jar".
#!/usr/bin/env python
import subprocess
import sys
import tempfile
import shutil
import os
import errno
# variables for checkstyle
@landys
landys / java_checks.xml
Created November 24, 2015 10:08
Java checkstyle xml based on google's with looser rules.
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!--
Checkstyle configurartion that checks the Google coding conventions from:
- Google Java Style
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@landys
landys / gist:cd3a5fdc769d576d578f
Created March 21, 2015 06:59
Setting header instead of adding header with proxy_pass and proxy_hide_header in Nginx
location ~ /dl/.*\.(jpg|png)$ {
proxy_pass http://test.51bmb.com;
proxy_hide_header Content-Type;
rewrite ^/(.*)/dl/(.*)$ /$1/$2 break;
root /mnt/data/bmbtest;
add_header Content-Type application/octet-stream;
add_header Content-Disposition "attachment;filename=qrcode.png";
expires 30d;
}
#!/bin/sh
cd platforms/ios
plugins_path=baomingba/Plugins/
add_plugin() {
find "$plugins_path$1" -name "*.[mh]*" -exec thor xcs:add {} Plugins \;
}
@landys
landys / talkbubble.html
Created December 29, 2014 08:43
Talking bubble with CSS.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<style type="text/css">
@landys
landys / yuiminify.sh
Last active August 29, 2015 14:11
Merge and minify css or js files with yuicompressor.
#!/bin/bash
# Wang Jinde
# Modify YUI_PATH with the path to the yuicompressor jar file
YUI_PATH="/opt/yui/yuicompressor-2.4.8.jar"
usage()
{
echo "usage: `basename "$0"` css/js outer_file source_files"
echo "I.E."