Skip to content

Instantly share code, notes, and snippets.

Eran Z srgrn

  • Israel
Block or report user

Report or block srgrn

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
@srgrn
srgrn / proxy.go
Created Oct 26, 2019
a simple proxy to convert basic auth to token auth
View proxy.go
package main
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"strings"
@srgrn
srgrn / linkheaderpagination.py
Created Feb 28, 2018
Django DRF LinkHeaderPagination
View linkheaderpagination.py
from rest_framework import pagination
from rest_framework.response import Response
class LinkHeaderPagination(pagination.CursorPagination):
def paginate_queryset(self, queryset, request, view=None):
try:
self.count = queryset.count()
except (AttributeError, TypeError):
self.count = len(queryset)
return super().paginate_queryset(queryset, request, view=None)
@srgrn
srgrn / DyanmicFieldSeriazliers.py
Created Feb 28, 2018
django_dyamic_field_serializer
View DyanmicFieldSeriazliers.py
from rest_framework import serializers
from rest_framework.utils import model_meta
from django.db.models.fields import Field as DjangoModelField
from django.db.models.fields import FieldDoesNotExist
class DynamicAppendFieldsModelSerializer(serializers.ModelSerializer):
"""
A ModelSerializer that takes an additional `fields` argument that
controls which fields should be displayed.
"""
@srgrn
srgrn / check_dockerinfo
Created Jul 20, 2017
Docker info for nagios
View check_dockerinfo
#!/bin/bash
infotext=$(docker info -f 'Containers {{.Containers}}, Running {{.ContainersRunning}}, Stopped {{.ContainersStopped}}, KernelVersion:{{.KernelVersion}} DockerVersion:{{.ServerVersion}} OS:{{.OperatingSystem}}')
infoGraph=$(docker info -f '|Total={{.Containers}},Running={{.ContainersRunning}}, Stopped={{.ContainersStopped}}')
RESULT=$?
output="OK"
if [ $RESULT -eq 1 ]
then
echo "CRITICAL- Docker not running"
View keybase.md

Keybase proof

I hereby claim:

  • I am srgrn on github.
  • I am eran (https://keybase.io/eran) on keybase.
  • I have a public key ASDpcNfDcioQA9vcUTNrjPweE8CJxRBIuAsaM2lgEnYuwgo

To claim this, I am signing this object:

@srgrn
srgrn / Vagrantfile
Created Mar 5, 2017
Simple vagrant file for devops linux course
View Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "arch" do |arch|
arch.vm.box = "ogarcia/archlinux-x64"
end
config.vm.define "ubuntu" do |ubuntu|
ubuntu.vm.box = "ubuntu/xenial64"
end
config.vm.network "private_network", type: "dhcp"
end
@srgrn
srgrn / line_by_line_python3.py
Created Nov 17, 2016
download a gzipped file line by line (for example http://csr.lanl.gov/data/cyber1/ files)
View line_by_line_python3.py
import urllib.request
import gzip
N = 200000
def read_line_by_line(url,handlefunc,**kwargs):
with gzip.open(urllib.request.urlopen(url),'r') as f:
for i in range(N):
try:
arr =f.readline().decode('ascii').strip().split(',')
handlefunc(arr,kwargs)
View azure_uploader.py
""" simple azure uploader script """
import sys
import argparse
import os
from azure.storage.blob import BlockBlobService
import logging
LOG_LEVEL = 'WARNING'
@srgrn
srgrn / scriptname.bat
Created May 30, 2016
Simple Jenkins Batch runner for powershell scripts - replace the scriptname.bat to the powershell script name.
View scriptname.bat
@ECHO OFF
PowerShell.exe -NoProfile -NonInteractive -ExecutionPolicy unrestricted -Command "& %~d0%~p0%~n0.ps1" %*
EXIT /B %errorlevel%
@srgrn
srgrn / runner.sh
Created May 8, 2016
simple python runner that runs a python script in a given virtual env for cron
View runner.sh
VIRTUALENV=$1
SCRIPT=$2
PARAMS="${@:3}"
source $VIRTUALENV/bin/activate
if [ -f $(dirname $SCRIPT)/requirements.txt ]
then
pip install -r $(dirname $SCRIPT)/requirements.txt
fi
python $SCRIPT $PARAMS
You can’t perform that action at this time.