Skip to content

Instantly share code, notes, and snippets.

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestPermissions();
scheduleWork();
}
private void scheduleWork() {
// Set constraints for the work (optional)
curl https://get.docker.com | bash -s
@zerowebcorp
zerowebcorp / docker-swarm-auto-rebalance.sh
Created December 10, 2017 17:08
Docker Swarm automatically rebalance when new worker node joins
FILE=/tmp/worker.nodes
touch ${FILE} || exit
for node in `docker node ls --filter role=worker -q`; do
if grep -Fxq "${node}" ${FILE}
then
echo "This node ${node} already exists"
else
echo "This node ${node} joined recently, so rebalance"
for service in `docker service ls -q`; do
@zerowebcorp
zerowebcorp / aws-s3-list-bucket-size.sh
Last active August 4, 2020 07:12
AWS S3 List all buckets size
for dir in $(aws s3 ls | awk '{print $3'}); do
size=$(aws s3 ls s3://${dir} --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}');
echo "${dir} => $size" | tee -a disk.txt
done
<?php
$db->between('created', '2014-05-05', '2014-05-10');
// Produces: created BETWEEN '2014-05-05' AND '2014-05-10'
$db->from('tblinvoices')->where('clientid', '12')->between('created', '2014-05-05' , '2014-05-10')->fetch();
// Produces: SELECT * FROM tblinvoices WHERE clientid = '12' AND created BETWEEN '2014-05-05' AND '2014-05-10'
@zerowebcorp
zerowebcorp / find_in_set.php
Last active August 29, 2015 14:12
Find In Set
<?php
$db->find_in_set('503', 'orders')->from('tblinvoices')->fetch();
// Produces: SELECT * FROM tblinvoices WHERE FIND_IN_SET ('305', orders)
$db->where('id', 5)->find_in_set('503', 'orders')->from('tblinvoices')->fetch();
// Produces: SELECT * FROM tblinvoices WHERE id='5' AND FIND_IN_SET ('305', orders)
$db->where('id', 5)->find_in_set('503', 'orders', 'OR')->from('tblinvoices')->fetch();
// Produces: SELECT * FROM tblinvoices WHERE id='5' OR FIND_IN_SET ('305', orders)
@zerowebcorp
zerowebcorp / php-mysql-get-changes.php
Last active August 29, 2015 14:04
PHP Snippt to get the changes caused by the UPDATE query
<?php
// Get the entire row before we update and save it in $row
$row = $db -> where('id', $id) -> from('tblorders') -> fetch_first();
// This will execute SELECT * FROM tblorders WHERE id = '12' ; I am using PHP
// MYSQLi wrapper from https://bitbucket.org/getvivekv/php-mysqli-class/
// Now perform the UPDATE query
$data['email'] = 'someemail';
$data['firstname'] = 'Vivek';
@zerowebcorp
zerowebcorp / Hash.php
Last active August 29, 2015 14:01
Simple functions to encode a password in PHP
<?php
class Password_Hash
{
public static function hash($password)
{
return hash("sha512", $password);
}
@zerowebcorp
zerowebcorp / adblock.html
Created October 13, 2012 09:43
jQuery AdBlock Detection HTML
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"> </script>
<script src="advertisement.js"></script>
<script>
$(function(){
if($.ads == undefined)
alert("Ads are disabled");
});
</script>
@zerowebcorp
zerowebcorp / jquery.adblock.js
Created October 13, 2012 09:24
jQuery AdBlock Detection
/*
* jQuery AdBlock Detection
* Author: Vivek
* Web: http://www.vivekv.com
*
* Create a file named advertisement.js with this one line content "$.ads = true;"
* Then include the file in your html.
*/