Skip to content

Instantly share code, notes, and snippets.

View naderio's full-sized avatar

Nader Toukabri naderio

View GitHub Profile
@naderio
naderio / script.sh
Last active October 13, 2015 22:18
Bash script file-based lock
#!/bin/bash
LOCK='path/to/file.lock'
[ -f "$LOCK" ] && { echo 'locked' >&2; exit 1; } || { touch "$LOCK" && trap 'rm -f "$LOCK"; exit $?' INT TERM EXIT; } || { echo 'unable to lock' >&2; exit 2; }
# processing
@naderio
naderio / README.md
Last active December 12, 2015 00:59
CORS with node.js and jQuery.

Test

node hello-service.js to run service on port 8081, test with curl http://localhost:8081/ and curl -X POST -d name=John in terminal

serve -p 8080 . to run app on port 8080 (temporary static content server), test http://localhost:8080/ in browser

Parameter Serie 1 Serie 2 Serie 3
1 10 17 5
2 12 13 5
3 14 15 10
@naderio
naderio / index.html
Last active August 29, 2015 14:24
Conditionally load WebComponents polyfill for use with Polymer, fire `WebComponentsReady` anyway
<script>
if ('registerElement' in document
&& 'createShadowRoot' in HTMLElement.prototype
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')) {
(function () {
function ready() {
setTimeout(function () {
document.dispatchEvent(new CustomEvent('WebComponentsReady', {
bubbles: true
@naderio
naderio / test-app.html
Created July 18, 2015 04:42
Recreature and reattache custom elements depending on state property' value
<dom-module id="test-app">
<style>
:host {
display: block;
}
</style>
<template>
...
<template is="dom-if" if="{{isState(state, 'home')}}" restamp="true">
<feed-view count="{{count}}"></feed-view>
@naderio
naderio / battery.android.js
Last active January 30, 2016 20:14
NativeScript Android battery service
'use strict';
const application = require('application');
const observable = require('data/observable');
const events = require('~/common/events');
const debug = require('nativescript-debug')(__filename);
@naderio
naderio / orientation.android.js
Created January 30, 2016 20:15
NativeScript Android orientation service
'use strict';
const application = require('application');
const observable = require('data/observable');
const events = require('~/common/events');
const params = require('~/common/params');
@naderio
naderio / location.android.js
Last active January 12, 2017 14:36
NativeScript Android location service based on Google Play services location APIs
'use strict';
const application = require('application');
const observable = require('data/observable');
const events = require('~/common/events');
const params = require('~/common/params');
@naderio
naderio / sample.js
Created January 30, 2016 20:38
NativeScript/Android: drawing polyline for Google Directions API response on Google Map
const debug = require('nativescript-debug')(__filename);
const application = require('application');
const observable = require('data/observable');
const LatLng = com.google.android.gms.maps.model.LatLng;
const PolylineOptions = com.google.android.gms.maps.model.PolylineOptions;
const LatLngBounds = com.google.android.gms.maps.model.LatLngBounds;
const CameraUpdateFactory = com.google.android.gms.maps.CameraUpdateFactory;
@naderio
naderio / socket.io.android.js
Created February 22, 2016 18:03
socket.io implementation in NativeScript/Android based on socketio/socket.io-client-java
'use strict';
var observable = require("data/observable");
const events = require('~/common/events');
const params = require('~/common/params');
const config = require('~/common/config');
const erros = require('~/common/error');