Skip to content

Instantly share code, notes, and snippets.

View ggendre's full-sized avatar

Guillaume Gendre ggendre

View GitHub Profile
@ggendre
ggendre / qml_side.js
Created September 10, 2013 10:12
BlackBerry10 AJAX Fix via QML fix ajax calls via a QML gateway. see story here (fr) : http://www.haploid.fr/blog/2013/09/10/blackberry10-et-ajax/
/* bind handleAjax native function to a message sent by the webview JavaScript
send result to webview
*/
WebView {
id : webview
onMessageReceived: {
try {
if (message && message.data) {
var jsonObj = JSON.parse(decodeURIComponent(message.data));
@ggendre
ggendre / init_bb10_extract.js
Created July 12, 2013 15:57
a raw (maybe not working) example on how to send back and forth ajax informations to BB10 qml native side
//fix BB10 ajax calls with a native patch
var lib=window.Zepto || window.jQuery;
lib.ajax=function(options){
navigator.cascades.postMessage(JSON.stringify({ action:"ajax", options:options }));
navigator.cascades.onmessage = function(message){
var params=JSON.parse(message);
if (params.action=="ajaxCallback"){
if (params.success && options.success){
options.success(params.data);
@ggendre
ggendre / main_qml_extract.js
Last active December 19, 2015 16:39
how to make an ajax call on BB10 native (JS) side
//ajax call on BB10 JS side, based on jquery $.ajax options
function handleAjaxCall(options,callback){
var url= options.url;
var type= (options.type in [ 'POST', 'GET' ]) ? options.type : "GET"; //default to GET
var data = options.data ? options.data : {}; //default to empty params
var request = new XMLHttpRequest();
request.onreadystatechange=function() {
if(request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200) {
@ggendre
ggendre / ninepatch.css
Last active December 11, 2015 17:38 — forked from anonymous/ninepatch.css
/*
Use this code to create a background with a nine patch image.
here, 22px is the size of a corner. the full image should have 4 corners of the same width & height.
And be bigger than 44x44 in this case.
Non symetrical images is also possible but far more complicated.
*/
.ninepatch{
border-width: 22px;
border-image: url(img/content_background.png) 22 22 22 22 repeat;
-webkit-border-image: url(img/content_background.png) 22 22 22 22 repeat;
/*
Use this to enable divs with overflow:scroll to scroll in android <3 web views.
Useful for phonegap apps.
Be sure to test for device first.
Usage example (needs jquery or zepto lib):
if (android_2){
enableTouchScroll( $('#myCrollableContent'), { x: true, y: true } );
}
*/
function enableTouchScroll(selector, axis){
@ggendre
ggendre / gist:4072478
Created November 14, 2012 14:36
connect to a reddis server from a python instance on dotcloud
"""
This is how to connect to a reddis server from a python instance on dotcloud
This assume that you have something like this in your dotcloud.yml
data:
type: redis
And that you added "redis" to the list in your requirements.txt pip file.
"""
import json
with open('/home/dotcloud/environment.json') as f:
@ggendre
ggendre / mysqlconnect.php
Created April 5, 2012 08:19
php mysql small connection script
<?php
if ( !isset($_GET['host']) || !isset($_GET['login']) ||
!isset($_GET['pwd']) || !isset($_GET['base'])
){
echo "<h4>script usage : </h4><ul><li>mysqlconnect.php?host=<b>yourHost</b>&login=<b>yourLogin</b>&pwd=<b>yourPassword</b>&base=<b>yourDatabase</b></li></ul>";
}else{
$connection = mysql_connect($_GET['host'],$_GET['login'],$_GET['pwd']);
if ( !$connection ){
die ("can't connect");
mysql_error();
@ggendre
ggendre / gist:1497638
Created December 19, 2011 15:20
python convert from formated datetime string to datetime
from datetime import datetime
import time
time.mktime(datetime.strptime("2011-12-19 15:35:54", '%Y-%m-%d %H:%M:%S').timetuple())
#-> 1324305354.0
@ggendre
ggendre / gist:1497636
Created December 19, 2011 15:20
python convert from datetime to timestamp
from datetime import datetime
mydatetime = datetime.now()
import time
time.mktime(mydatetime.timetuple())
#-> 1324305354.0
@ggendre
ggendre / gist:1497633
Created December 19, 2011 15:19
python convert from timestamp to datetime
from datetime import datetime
datetime.fromtimestamp(1324305354.0857329)
#-> datetime.datetime(2011, 12, 19, 15, 35, 54, 85733)