Skip to content

Instantly share code, notes, and snippets.

💼
Learning React

Emin Buğra Saral ebsaral

💼
Learning React
Block or report user

Report or block ebsaral

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
@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_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 / 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 / capybara_example.rb
Last active Aug 29, 2015
Capybara Example
View capybara_example.rb
require 'capybara'
class CapybaraHelper
attr_accessor :session
def initialize
# Register Chrome driver
# You might need to install Chrome Driver to make it run (e.g 'brew install chromedriver')
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
@ebsaral
ebsaral / video_wants_to_watch.m
Last active Aug 29, 2015
Sending an Open Graph message with video.wants_to_watch action
View video_wants_to_watch.m
// In order to display a Open Graph Action in your Facebook Share Dialog (FBDialog), you can construct your code like this:
NSMutableDictionary<FBOpenGraphAction> *action = (NSMutableDictionary<FBOpenGraphAction> *)[FBGraphObject graphObject];
NSMutableDictionary *graphObject = [FBGraphObject openGraphObjectForPostWithType:@"video.movie"
title:@"My movie."
image:@"http://www.mymovie.com/poster.jpg"
url:@"http://www.mymovie.com"
description:@"This movie may contain adult material."];
action[@"movie"] = graphObject;
@ebsaral
ebsaral / 16-base32.py
Last active Aug 29, 2015
Generating random string encoded in base32 with Python
View 16-base32.py
import base64
import random
def generate_16char_base32(pre):
"""
Encode a string of 16 length in base32
with a given string - maximum length of 10 chars -
Note: 10 char = 16 char string in base32
Warning: Decoding is not a part of this example
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
You can’t perform that action at this time.