Skip to content

Instantly share code, notes, and snippets.

View amirouche's full-sized avatar

Amir Amazigh BOUBEKKI amirouche

View GitHub Profile
@amirouche
amirouche / call-python.txt
Last active August 29, 2015 14:01
create a shared lib to call python code
This doesn't compile Python to machine code. But allows to create a shared library to call Python code.
If what you are looking for is an easy way to run Python code from C without relying on execp stuff. You could generate a shared library from python code wrapped with a few calls to [Python embedding API][1]. Well the application is a shared library, an .so that you can use in many other libraries/applications.
Here is a simple example which create a shared library, that you can link with a C program. The shared library executes Python code.
The python file that will be executed is `pythoncalledfromc.py`:
# -*- encoding:utf-8 -*-
# this file must be named "pythoncalledfrom.py"
@amirouche
amirouche / getting.started.with.react.md
Last active August 29, 2015 14:12
Getting started with react
  • Install npm and nodejs (on debian I had to link /usr/bin/nodejs to /usr/bin/node
  • At the root of your project create package.js file with the an empty json object:
$ echo "{}" > package.js 

In the same directory, install all the project dependencies with the following command:

@amirouche
amirouche / aiohttp+websockets.md
Last active January 17, 2022 09:14
aiohttp server with websocket

** aiohttp now supports in its webframework websocket **

http://aiohttp.readthedocs.org/en/v0.14.1/web.html#websockets

This is a quick hack (ported from django-c10k) to get websocket working along side classic http with aiohttp web server. I think it would be better to inherit the aiohttp.web.RequestHandler and add the code to handle the upgrade in RequestHandler.start instead of overriding RequestHandler.transport.close in WebsocketResponse.

Anyway, it seems like it works.

requirements:

@amirouche
amirouche / app.js
Last active August 29, 2015 14:15
facebook css-layout example
/* layout debug */
[].forEach.call(
document.querySelectorAll("*"),
function(a){
a.style.outline="1px solid hsl(" + Math.random() * 360 +", 70%, 70%)";
}
)
function elementToLayoutTree(element){
@amirouche
amirouche / async-snippets.py
Created April 28, 2015 15:52
#hypermove #python #asyncio
from aiohttp import request
from lxml.html import parse
def downfile():
r = yield from request('get', 'http://python.org')
raw = yield from r.text()
return raw
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(run())
@amirouche
amirouche / bashrc.sh
Last active August 29, 2015 14:20
bash snippets
# user https://wiki.archlinux.org/index.php/Color_Bash_Prompt#Regular_user
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'
# root
PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[0;31m\]\$ \[\e[m\]\[\e[0;32m\]'
@amirouche
amirouche / magna.py
Created April 30, 2015 17:40
Declarative syntax #hypermove #python #python3
class Property:
def __init__(self, *variables, **options):
self.variables = variables
self.options = options
self.name = None
def __get__(self, obj, klass):
print(obj)
return obj._values[self.name]
import asyncio
import shlex
# inspired by https://docs.python.org/3/library/asyncio-subprocess.html
class CheckOutput(asyncio.SubprocessProtocol):
def __init__(self, exit_future):
self.exit_future = exit_future
self.output = bytearray()
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index b607900..c7efd49 100644
--- a/django/db/models/manager.py
+++ b/django/db/models/manager.py
@@ -179,7 +179,14 @@ class BaseManager(six.with_metaclass(RenameManagerMethods)):
Returns a new QuerySet object. Subclasses can override this method to
easily customize the behavior of the Manager.
"""
- return self._queryset_class(self.model, using=self._db, hints=self._hints)
+ queryset = self._queryset_class(self.model, using=self._db, hints=self._hints)
#!/usr/bin/env python3
import os
import mimetypes
from asyncio import coroutine
from asyncio import get_event_loop
from aiohttp.web import Application
from aiohttp.web import StaticRoute
from aiohttp.web import HTTPNotFound
from aiohttp.web import HTTPMovedPermanently