Skip to content

Instantly share code, notes, and snippets.

View hbasria's full-sized avatar

Basri hbasria

  • base9.tech
  • ///soak.massing.glory
View GitHub Profile
CREATE OR REPLACE FUNCTION is_private_ip(p_prefix inet) RETURNS boolean AS
$BODY$
BEGIN
RETURN (
SELECT
CASE
WHEN '10.0.0.0/8'::inet >> p_prefix::inet
OR '192.168.0.0/16'::inet >> p_prefix::inet
OR '172.16.0.0/12'::inet >> p_prefix::inet THEN True
@hbasria
hbasria / knife cheat
Last active August 29, 2015 14:27 — forked from ipedrazas/knife cheat
Hello!
# knife cheat
## Search Examples
knife search "name:ip*"
knife search "platform:ubuntu*"
knife search "platform:*" -a macaddress
knife search "platform:ubuntu*" -a uptime
knife search "platform:ubuntu*" -a virtualization.system
knife search "platform:ubuntu*" -a network.default_gateway
@hbasria
hbasria / redis_bulk.sh
Created October 27, 2015 07:24 — forked from egemenyildiz/redis_bulk.sh
[LUA] Redis bulk/batch operation scripts (rename, delete)
# Bulk deletes keys start with "prefix"
EVAL "for i, name in ipairs(redis.call('KEYS', 'prefix*')) do redis.call('DEL', name); end" 0
# Bulk renames keys start with "prefix" to "postfix".
# e.g. prefixwithtail -> postfixwithtail
EVAL "for i, name in ipairs(redis.call('KEYS', 'prefix*')) do local x = string.gsub(name, 'pre', 'post'); redis.call('RENAME', name, x); end" 0
@hbasria
hbasria / gist:f8e21c3bda47bd00d339
Created November 18, 2015 16:05 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
SELECT * FROM tree
left join (
SELECT
generate_series as id,
case
when generate_series = 0 then 'CREATED'
when generate_series = 1 then 'PENDING'
when generate_series = 2 then 'RECEIVED'
when generate_series = 3 then 'STARTED'
when generate_series = 4 then 'RETRY'
@hbasria
hbasria / raw_as_qs.py
Created January 29, 2016 14:03 — forked from carymrobbins/raw_as_qs.py
Django - convert RawQuerySet to QuerySet
from django.db import connection, models
class MyManager(Manager):
def raw_as_qs(self, raw_query, params=()):
"""Execute a raw query and return a QuerySet. The first column in the
result set must be the id field for the model.
:type raw_query: str | unicode
:type params: tuple[T] | dict[str | unicode, T]
:rtype: django.db.models.query.QuerySet
"""
@hbasria
hbasria / docker_volume_rm.sh
Created March 8, 2016 12:59
docker volume rm
docker volume rm $(docker volume ls -qf dangling=true)
SELECT
pgClass.relname AS tableName,
pgClass.reltuples AS rowCount
FROM
pg_class pgClass
LEFT JOIN
pg_namespace pgNamespace ON (pgNamespace.oid = pgClass.relnamespace)
WHERE
pgNamespace.nspname NOT IN ('pg_catalog', 'information_schema') AND
pgClass.relkind='r'
@hbasria
hbasria / ping.py
Created April 5, 2016 17:52 — forked from pklaus/ping.py
A pure python ping implementation using raw socket.
#!/usr/bin/env python2
"""
Other Repositories of python-ping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* https://github.com/l4m3rx/python-ping supports Python2 and Python3
* https://bitbucket.org/delroth/python-ping
import socket, struct, os, array
from scapy.all import ETH_P_ALL
from scapy.all import select
from scapy.all import MTU
#author: askldjd
#see: http://wp.me/pDfjR-rQ
class IPSniff:
def __init__(self, interface_name, on_ip_incoming, on_ip_outgoing):