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 / 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
@amirouche
amirouche / .emacs
Created May 29, 2015 17:26
my humble .emacs
(require 'package)
;; todo
;; - bind marks commands
(add-to-list
'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(add-to-list