Skip to content

Instantly share code, notes, and snippets.

View hsleonis's full-sized avatar
🏝️
Travellers unite.

Hasan Shahriar hsleonis

🏝️
Travellers unite.
View GitHub Profile
@hsleonis
hsleonis / logger.py
Created January 2, 2018 11:35
Python logger
import logging
# create logger
logger = logging.getLogger("logging_tryout2")
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
@hsleonis
hsleonis / csv-generate.py
Created January 2, 2018 11:34
CSV generate
def profile(request):
response_model = generate_response(request)
# Generate CSV
from django.http import HttpResponse
import csv
users = User.objects.all()
response = HttpResponse(content_type='text/csv')
@hsleonis
hsleonis / middleware.py
Created November 27, 2017 10:19
Django Login Required Middleware
from django.shortcuts import HttpResponseRedirect
#from employee.models import UserProfile
class LoginRequiredMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
:: Run the following command in your project to save your currently installed plugins into config.xml:
cordova plugin save
:: To upgrade
npm install -g cordova
cd my_project
cordova platform rm ios
cordova platform add [email protected]
@hsleonis
hsleonis / Djangocreator.bat
Last active November 14, 2017 06:49
Generate basic django project on windows
@echo off
set /p UserInputPath= Enter directory name :
:: mkdir %UserInputPath%
:: mkvirtualenv biman
:: workon biman
:: pip install django
:: pip install django-admin
django-admin startproject %UserInputPath%
@hsleonis
hsleonis / wp-delete-revisions.php
Created March 9, 2017 06:16
WP remove all revisioons
<?php
global $wpdb;
if ( check_admin_referer( plugin_basename( __FILE__ ) ) ) {
$revisions = $wpdb->get_results(
"SELECT 'ID' AS revision_id
FROM ($wpdb->posts)
WHERE 'post_type' = 'revision'
ORDER BY 'ID' DESC"
);
@hsleonis
hsleonis / wp-custom-attachment-fields.php
Created March 6, 2017 10:34
Add custom fields in attachment page
<?php
add_action( 'attachment_fields_to_edit', array($this, 'tmx_attachment_fields_to_edit'), 10, 2 );
public function tmx_attachment_fields_to_edit( $form_fields, $post ){
// Apply only in image attachment pages
if( $post->post_mime_type == 'image/jpeg' || $post->post_mime_type == 'image/jpg' || $post->post_mime_type == 'image/png' ){
$form_fields['tmx-apply-filter-sbutton'] = array(
'label' => __('Add Image effects', 'themeaxe'),
'input' => 'html',
@hsleonis
hsleonis / wp-admin-page-without-menu.php
Created March 6, 2017 10:29
WP admin page without showing link in menu
<?php
add_action( 'admin_menu', array( $this, 'tmx_custom_admin_page' ) );
public function tmx_custom_admin_page(){
add_submenu_page( 'upload.php', __('Custom images', 'themeaxe'), __('Custom images','themeaxe'), 'manage_options', 'custom-admin-page', array($this, 'tmx_custom_admin_page_callback') );
remove_submenu_page( 'upload.php', 'custom-admin-page' );
}
public function tmx_custom_admin_page_callback() {
@hsleonis
hsleonis / admin-custom-image-page.php
Last active April 6, 2018 05:43
WP save attachment with AJAX
<div id="tmx-image" data-img="<?php echo wp_get_attachment_url( $_GET['attachment_id'] ); ?>">
</div>
<script>
var tmx_img = $('#tmx-image').data('img');
$('#tmx-save').on('click',function(){
Caman("#tmx-image",tmx-image, function () {
// this = formatted image using Caman JS for example
var new_image = this.toBase64();
@hsleonis
hsleonis / wp-related-posts.php
Created February 3, 2017 05:23
WP Related Posts by Categories