Skip to content

Instantly share code, notes, and snippets.

View balavec's full-sized avatar
😎
Working on a migration to Plone 5.2

Robert Kuzma balavec

😎
Working on a migration to Plone 5.2
View GitHub Profile

Keybase proof

I hereby claim:

  • I am balavec on github.
  • I am balavec (https://keybase.io/balavec) on keybase.
  • I have a public key ASBiLhA9bbf-ah1CQFPxtgw5ipIODHN0AjhgV20VEH1I1go

To claim this, I am signing this object:

@balavec
balavec / django_model_deletable.py
Created August 16, 2020 20:04 — forked from freewayz/django_model_deletable.py
Django check if model has related object before Deleting the model
#After looking for a way to check if a model instance can be deleted in django ,
#i came across many sample, but was not working as expected. Hope this solution can help.
#Let start by creating an Abstract model class which can be inherited by other model
class ModelIsDeletable(models.Model):
name = models.CharField(max_length=200, blank=True, null=True, unique=True)
description = models.CharField(max_length=200, blank=True, null=True)
date_modified = models.DateTimeField(auto_now_add=True)
@balavec
balavec / curl.md
Created June 5, 2020 09:34 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@balavec
balavec / delete_local_branches.sh
Created July 29, 2019 12:33 — forked from TSMMark/delete_local_branches.sh
Delete local branches that don't exist remotely
git fetch --all -p; git branch -vv | grep ": gone]" | awk '{ print $1 }' | xargs -n 1 git branch -D
@balavec
balavec / iterm2-solarized.md
Created December 15, 2018 14:14 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

/* Make sure jQuery is available. */
/* Make sure you have proper URL. */
$.ajax({
url: "/_api/web/lists/GetByTitle('ListName')/Items",
headers:
{
"Accept": "application/json;odata=nometadata",
"Content-Type": "application/json;odata=nometadata",
"odata-version": ""
},
@balavec
balavec / percentile.js
Created April 29, 2018 18:29 — forked from IceCreamYou/percentile.js
Utility functions to calculate percentiles and percent ranks in a JavaScript array.
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];
var index = arr.length * p,
lower = Math.floor(index),
@balavec
balavec / dd.php
Created January 9, 2018 09:46 — forked from james2doyle/dd.php
A implementation of "dump and die" (dd) for WordPress
<?php
if (!function_exists('dd')) {
function dd($data)
{
ini_set("highlight.comment", "#969896; font-style: italic");
ini_set("highlight.default", "#FFFFFF");
ini_set("highlight.html", "#D16568");
ini_set("highlight.keyword", "#7FA3BC; font-weight: bold");
ini_set("highlight.string", "#F2C47E");
@balavec
balavec / useful_pandas_snippets.py
Created December 6, 2016 11:38 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]
@balavec
balavec / cuter.py
Created October 15, 2015 15:45 — forked from sigilioso/cuter.py
Python PIL Example: get a thumbnail by resizing and cropping an image.
# -*- coding: utf-8 -*-
import Image
def resize_and_crop(img_path, modified_path, size, crop_type='top'):
"""
Resize and crop an image to fit the specified size.
args:
img_path: path for the image to resize.