Skip to content

Instantly share code, notes, and snippets.

Avatar
💼
Learning React

Emin Buğra Saral ebsaral

💼
Learning React
View GitHub Profile
@ebsaral
ebsaral / ex_migration_script.py
Created Jul 12, 2017
Converting a model to multi-table inheritance in Django - Migration Script
View ex_migration_script.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class CopyFieldsBetweenTables(migrations.operations.base.Operation):
reversible = False
def __init__(self, model_from_name, model_to_name, columns):
@ebsaral
ebsaral / error.js
Created Oct 27, 2020
JS Simple error
View error.js
throw new Error('ERROR!');
@ebsaral
ebsaral / example_hfexcel_template.json
Created May 26, 2019
Example HFExcel JSON Template
View example_hfexcel_template.json
{
"sheets": [
{
"key": "sheet1",
"name": "Example Sheet 1",
"columns": [
{
"name": "Column 1",
"width": 2,
"args": [
@ebsaral
ebsaral / replace_duplicates.py
Last active Aug 8, 2017
Replace duplicate objects with the original
View replace_duplicates.py
from django.db import transaction
from django.db.models.deletion import Collector
from django.db.models.fields.related import ForeignKey, ManyToManyField, OneToOneField
duplicates = []
items = {}
client = Client.objects.get(name='Demo')
for c in Company.objects.filter(active=True, client=client):
company_name = c.name
@ebsaral
ebsaral / ex_final_model_structure.py
Created Jul 12, 2017
Converting a model to multi-table inheritance in Django - Final Model Structure
View ex_final_model_structure.py
class Address(models.Model):
name = models.CharField(max_length=20)
owner = models.ForeignKey('another_app.Owner')
class HomeAddress(Address):
housekeeper = models.CharField(max_length=50)
class WorkAddress(Address):
@ebsaral
ebsaral / ex_initial_model_structure.py
Created Jul 12, 2017
Converting a model to multi-table inheritance in Django - Initial Model Structure
View ex_initial_model_structure.py
class Address(models.Model):
name = models.CharField(max_length=20)
owner = models.ForeignKey('another_app.Owner')
class Meta:
abstract = True
class HomeAddress(Address):
housekeeper = models.CharField(max_length=50)
@ebsaral
ebsaral / gist:4408664
Last active Oct 27, 2016
Brightness and Contrast adjustment in InDesign CS4 [MAC]
View gist:4408664
-- Author : Emin Bugra Saral
-- Author Website : http://www.eminbugrasaral.com
-- Sources : http://www.adobe.com/products/indesign/scripting/pdfs/InDesignCS4_ScriptingGuide_AS.pdf
-- Purpose : Changing brightness and contrast of an image in InDesign CS4 by using Photoshop CS4
-- Warning: Please be sure you read "readme.txt"
tell application "Adobe InDesign CS4"
activate
-- default values :
set defaultBValue to 80
View custom_adminsite_menu.py
import my_app
@register.assignment_tag(takes_context=True)
def get_menu(context, request):
"""
:type request: WSGIRequest
"""
if not isinstance(request, WSGIRequest):
return None
View ebsftp.sh
#!/bin/bash
echo "*** WELCOME TO FTP UPLOAD SCRIPT written by Emin Bugra Saral ***"
echo
# Variables
SOURCE_PATH="$1"
TARGET_PATH="$2"
FTP_SERVER_FILE="$(basename $0)_server.txt" # Info file's name
FTP_SERVER_FILE_DIR="$(pwd)/$FTP_SERVER_FILE" # Info file's directory which is current one
@ebsaral
ebsaral / gist:4132145
Created Nov 22, 2012
Capture frames from a webcam in MATLAB
View gist:4132145
function [ ] = takepicture( framenumber , frequency , enable_preview, foldername)
%TAKEPICTURE This function takes a snapshot from webcam
% framenumber = how many frames to be recorded
% frequency = if it's 5, 1 in 5 frames will be recorded. The higher is the
% faster.
% enable_preview = set true if you wanna preview the cam
% foldername = the folder where the pictures will be saved
% Close variables
close all;