Skip to content

Instantly share code, notes, and snippets.

Martin Martin91

Block or report user

Report or block Martin91

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Martin91
Martin91 / output.txt
Created Jun 12, 2019
supervisord XML/RPC API demo
View output.txt
==================== Supported Methods ======================
['supervisor.addProcessGroup', 'supervisor.clearAllProcessLogs', 'supervisor.clearLog', 'supervisor.clearProcessLog', 'supervisor.clearProcessLogs', 'supervisor.getAPIVersion', 'supervisor.getAllConfigInfo', 'supervisor.getAllProcessInfo', 'supervisor.getIdentification', 'supervisor.getPID', 'supervisor.getProcessInfo', 'supervisor.getState', 'supervisor.getSupervisorVersion', 'supervisor.getVersion', 'supervisor.readLog', 'supervisor.readMainLog', 'supervisor.readProcessLog', 'supervisor.readProcessStderrLog', 'supervisor.readProcessStdoutLog', 'supervisor.reloadConfig', 'supervisor.removeProcessGroup', 'supervisor.restart', 'supervisor.sendProcessStdin', 'supervisor.sendRemoteCommEvent', 'supervisor.shutdown', 'supervisor.signalAllProcesses', 'supervisor.signalProcess', 'supervisor.signalProcessGroup', 'supervisor.startAllProcesses', 'supervisor.startProcess', 'supervisor.startProcessGroup', 'supervisor.stopAllProcesses', 'supervisor.stopProcess'
@Martin91
Martin91 / groupby.py
Last active Sep 28, 2018
Python itertools.groupby trap
View groupby.py
data = [{'id': 1, 'value': 1}, {'id': 2, 'value': 2}, {'id': 2, 'value': 3}, {'id': 1, 'value': 4}]
for id, ele in groupby(data, key=lambda e: e['id']):
print "id: %d" % id
print "values: %s" % list(ele)
# => id: 1
# => values: [{'id': 1, 'value': 1}]
# => id: 2
# => values: [{'id': 2, 'value': 2}, {'id': 2, 'value': 3}]
# => id: 1
@Martin91
Martin91 / django_aggregation.py
Last active Aug 10, 2018
django work with aggregation functions
View django_aggregation.py
from django.db.models import Count
Model.values('pickup_plan_id').annotate(picked_count=Count('pickup_plan_id')).filter(picked_count__lt=2)
# SELECT
# `model`.`pickup_plan_id`,
# COUNT(`model`.`pickup_plan_id`) AS `picked_count`
# FROM
# `model`
# WHERE
@Martin91
Martin91 / iptables_allow_only_localhost.sh
Created Jul 22, 2018
iptables to allow only localhost to access specified port
View iptables_allow_only_localhost.sh
# Allow access only localhost by port 1991
sudo iptables -A INPUT -i lo -p tcp --dport 1991 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 1991 -j DROP
@Martin91
Martin91 / mime_types.json
Created Jul 20, 2018
incomplete MIME types
View mime_types.json
// refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
{
".aac": "audio/aac",
".abw": "application/x-abiword",
".arc": "application/octet-stream",
".avi": "video/x-msvideo",
".azw": "application/vnd.amazon.ebook",
".bin": "application/octet-stream",
".bmp": "image/bmp",
".bz": "application/x-bzip",
@Martin91
Martin91 / paramsconvert.py
Last active May 17, 2018
param convert according to json schema in python
View paramsconvert.py
from lib.errors import TypeConvertInvalid
SIMPLE_VALUE_TYPES = [str, int, float]
BOOLABLE_TYPES = SIMPLE_VALUE_TYPES[:]
BOOLABLE_TYPES.append(bool)
def convert(value, convert_func, parse_path, convertable_types=SIMPLE_VALUE_TYPES):
if type(value) in convertable_types:
try:
return convert_func(value)
@Martin91
Martin91 / dict_sort.py
Created May 8, 2018
python sort dictionary with value in desc order
View dict_sort.py
import collections
mydict = {
'a': 49023,
'b': 39201,
'c': 49021,
'd': 90201,
'e': 49012,
'f': 49401,
'g': 10039,
@Martin91
Martin91 / omg-git.git-show.sh
Last active Nov 20, 2017
search sensitive words in git history
View omg-git.git-show.sh
#!/usr/bin/env bash
NOT_GIT_REPO=1
if $(git rev-list --all &>/dev/null)
then
echo "Detect git repo, continue now..."
else
echo "Could not find any git repo here!"
exit $NOT_GIT_REPO
@Martin91
Martin91 / hash_addition.rb
Created Jun 2, 2017
ruby hashes addition
View hash_addition.rb
hash1 = {a: 100, b: [1, 2], c: "hello"}
hash2 = {a: 300, b: [3, 4, 5], c: " world", d: "fh"}
hash1.merge(hash2) { |key, val_f, val_r| val_f + val_r }
# => {:a=>400, :b=>[1, 2, 3, 4, 5], :c=>"hello world", :d=>"fh"}
@Martin91
Martin91 / application.rb
Created Mar 10, 2017
rails application decorator mechanism
View application.rb
config.to_prepare do
# Load application's model / class decorators
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end
You can’t perform that action at this time.