Skip to content

Instantly share code, notes, and snippets.

View mdemblani's full-sized avatar

Manish Demblani mdemblani

View GitHub Profile
@aaronpolhamus
aaronpolhamus / redis_handlers.py
Created August 9, 2020 02:06
task locking with redis + celery
"""Task locking with redis in celery is hard, and good examples are tough to come by. This is the approach that's
worked for me, based on great work that other folks have posted:
* https://breadcrumbscollector.tech/what-is-celery-beat-and-how-to-use-it-part-2-patterns-and-caveats/
* http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
* https://redis.io/topics/distlock
This isn't polished,but hopefully it's useful. To verify it in our local test env we register the following test task in
our definitions file:
*** definitions.py ***
@mdemblani
mdemblani / Mysql Character Set conversion - Latin1 to UTF-8(utf8mb4).md
Last active June 20, 2023 08:03
Mysql Character Set conversion - Latin1 to UTF-8(utf8mb4)
  1. Make sure mysql-client is installed. If not, then :
    sudo apt install mysql-client
	or
    sudo apt-get install mysql-client
  1. Open php.ini

; PHP's default character set is set to UTF-8.

@toddmotto
toddmotto / *.md
Last active April 25, 2023 09:06
Component versus Directive in AngularJS

Component versus Directive in AngularJS

.component()

Components are not "helper" methods, they are the best change in Angular 1.x since I've been using it.

What is the role of .component()?

  • Declares new HTML via a template or templateUrl
  • Should be used to create Components as part of a Component architecture
@mdemblani
mdemblani / CakePhp Rest Route with api prefi steps.md
Last active May 28, 2018 20:59
CakePhp Rest Route with api prefix. A small hack in cakephp v2.X Lib to support restful routes with api prefix

I had my api ready and faced the problem of converting them into rest routes with api and version prefixs using the cakephp Router::mapResources function that was provided by default by CakePhp,

My api was intially,
http://www.xyz.com/controller/
supporting basic rest routes and I wanted it to be in the form
http://www.xyz.com/api/version_number/controller/action
that would support basic rest routes with prefix including api and version number.

To achieve this there are two ways:

  1. Create routes using Router::connect for each function and list them down manually in your routes.php file.
@amochohan
amochohan / 01_Laravel 5 Simple ACL manager_Readme.md
Last active April 22, 2024 17:19
Laravel 5 Simple ACL - Protect routes by an account / role type

#Laravel 5 Simple ACL manager

Protect your routes with user roles. Simply add a 'role_id' to the User model, install the roles table and seed if you need some example roles to get going.

If the user has a 'Root' role, then they can perform any actions.

Installation

Simply copy the files across into the appropriate directories, and register the middleware in App\Http\Kernel.php

@jashkenas
jashkenas / semantic-pedantic.md
Last active November 29, 2023 14:49
Why Semantic Versioning Isn't

Spurred by recent events (https://news.ycombinator.com/item?id=8244700), this is a quick set of jotted-down thoughts about the state of "Semantic" Versioning, and why we should be fighting the good fight against it.

For a long time in the history of software, version numbers indicated the relative progress and change in a given piece of software. A major release (1.x.x) was major, a minor release (x.1.x) was minor, and a patch release was just a small patch. You could evaluate a given piece of software by name + version, and get a feeling for how far away version 2.0.1 was from version 2.8.0.

But Semantic Versioning (henceforth, SemVer), as specified at http://semver.org/, changes this to prioritize a mechanistic understanding of a codebase over a human one. Any "breaking" change to the software must be accompanied with a new major version number. It's alright for robots, but bad for us.

SemVer tries to compress a huge amount of information — the nature of the change, the percentage of users that wil

@jrencz
jrencz / README_PHPCS.md
Last active August 20, 2018 10:13
This tutorial describes how to set PHP_CodeSniffer as the local project dependency instead of the suggested global PEAR dependency.
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@robotlolita
robotlolita / loops-are-evil.md
Last active March 2, 2022 17:19
Why `xs.each(f)` should not be considered a "loop".

First and foremost, let's take a look at the following pieces of code. The first one is something you should be rather familiar with, and the second one is also a somewhat familiar idiom these days (at least in languages with higher-order functions):

// Example 1:
30 + 12

// Example 2:
xs.map(f)
@geon
geon / app_model.php
Created September 2, 2011 16:51
Get actual integers from MySQL with CakePHP.
<?php
class AppModel extends Model {
function afterFind($results){
if(!isset($results[0])){
// $results is a single object.
$results = $this->realAfterFind($results);