Skip to content

Instantly share code, notes, and snippets.

Avatar

ranelpadon

View GitHub Profile
View settings.json
{
"window.zoomLevel": -1,
"terminal.integrated.fontFamily": "MesloLGS NF",
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.cursorStyle": "line",
"editor.fontFamily": "Monaco, Menlo, 'Courier New', monospace",
"code-runner.fileDirectoryAsCwd": true,
"terminal.integrated.cwd": ".",
"terminal.integrated.shell.osx": "/usr/local/bin/zsh",
"atomKeymap.promptV3Features": true,
@ranelpadon
ranelpadon / karabiner.json
Last active Feb 23, 2021
Colemak DHk - Karabiner Elements - Config File
View karabiner.json
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
@ranelpadon
ranelpadon / django-formset--custom-kwarg--formset-save--model-save.py
Last active Jun 8, 2018
Custom Django model.save() kwarg to avoid executing costly codes if there are lots of formsets in the page.
View django-formset--custom-kwarg--formset-save--model-save.py
# forms.py
class EventSessionFormSet();
...
def save(self, commit=True):
sessions = []
forms = self.forms
total_forms = len(forms)
for i, form in enumerate(forms):
@ranelpadon
ranelpadon / multiple_replace.py
Last active Feb 17, 2018
Find the restricted symbols in the text and substitute with multiple replacement values.
View multiple_replace.py
import re
# Restricted symbols taken from https://en.wikipedia.org/wiki/Filename
symbols = ('/', '\\', '?', '%', '*', ':', '|', '"', '<', '>',)
symbols_replacements = {symbol: '_' for symbol in symbols}
space_replacement = {' ': '-'} # Dash instead of underscore
replacements = {}
replacements.update(symbols_replacements)
@ranelpadon
ranelpadon / django-dependent-field.js
Last active Aug 28, 2017
Update the select list field B based on the currently selected option in select list field A. For example, when you select a particular Music Genre, only the related Artists should show. Other common use cases/relationships: Country/Cities, Organization/Members, Company/Contact Persons, Brand/Products, etc.
View django-dependent-field.js
// Workflow (Genre is the Parent Field, Artist is the Dependent Field):
// 1. user interacts w/ Genre select list widget via JS script.
// 2. JS script fetches the new Artist list in views.py
// 3. JSON response will be used as the new values/options for the Artist select list widget.
(function($) {
$(function() {
// Artist's select option values will depend on
// the Genre's selected option.
var $genreSelectWidget = $('#id_genre');
@ranelpadon
ranelpadon / dependent-field.js
Created Aug 27, 2017
Update the select list field B based on the currently selected option in select list field A. For example, when you select a particular Music Genre only the related Artist should show. Other common use cases/relationships are Company/Contact Info, Country/City, or Brand/Products.
View dependent-field.js
(function($) {
$(function() {
// Artist's select option values will depend on
// the Genre's selected option.
var $genreSelectWidget = $('#id_genre');
var $artistSelectWidget = $('#id_artist');
var artistSelectWidgetInitial = $artistSelectWidget.val()
// Adjust Artists based on the selected Genre.
function adjustArtistOptions(preSelectedOption) {
@ranelpadon
ranelpadon / issues_with_deleting_objects.py
Last active Aug 29, 2015
Python's __del__ has some nasty issues when dealing with objects, list, garbage collection, etc.
View issues_with_deleting_objects.py
# Hypothetical class for saving the Universe.
class Particle:
def __init__(self, name):
self.name = name
print self.name, 'created'
def __del__(self):
print self.name, 'deleted'
# Create new particle objects.
@ranelpadon
ranelpadon / drupal_image_with_caption_block.php
Last active Aug 29, 2015
Create a Drupal block programmatically. This will create a block with an image and a tagline, demonstrating the use of theme function and render arrays
View drupal_image_with_caption_block.php
<?php
// HOW TO USE:
// Create a MY_MODULE.info file. See https://www.drupal.org/node/542202.
// Create a MY_MODULE.module file.
// Put the codes below in MY_MODULE.module file
// THE BIG PICTURE:
// For a block to work in Drupal, you have to do a minimum of 3 things:
// 1. Declare the block in hook_block_info().
@ranelpadon
ranelpadon / drupal_get_node_type.php
Last active Aug 29, 2015
Get the node type of the current node using EntityFieldQuery (EFQ) API.
View drupal_get_node_type.php
<?php
// Get the node id from the current page's URL.
$nid = arg(1);
// Create a new EFQ object.
$query = new EntityFieldQuery();
// Select the node entity with the target node id.
$query->entityCondition('entity_type', 'node');
@ranelpadon
ranelpadon / toolkit.drush.inc.php
Last active Aug 29, 2015
Custom Drush Commands Demo. Rename the file as toolkit.drush.inc ($ mv toolkit.drush.inc.php toolkit.drush.inc). Make it executable ($ sudo chmod a+x toolkit.drush.inc). Put this file in ~/.drush folder so that you will have now a ~/.drush/toolkit.drush.inc file.
View toolkit.drush.inc.php
<?php
/**
* Implements COMMANDFILE_drush_command().
*/
function toolkit_drush_command() {
$items = array();
// Command for Clear Cache All.
// The 'cca' array key is what you type in the terminal, like: drush cca.