Skip to content

Instantly share code, notes, and snippets.

@sultaniman
sultaniman / LocationService
Last active September 4, 2020 20:30
Android simple location service
package com.my.package.services;
import android.app.Service;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
public class MyFragment extends SupportMapFragment {
public static final String TAG = "MyFragment";
// Milliseconds per second
private static final int MILLISECONDS_PER_SECOND = 1000;
// Update frequency in seconds
public static final int UPDATE_INTERVAL_IN_SECONDS = 120;
// Update frequency in milliseconds
private static final long UPDATE_INTERVAL = MILLISECONDS_PER_SECOND * UPDATE_INTERVAL_IN_SECONDS;
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"arrowFunctions": false, // enable arrow functions
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"classes": false, // enable classes
"defaultParams": false, // enable default function parameters
"destructuring": false, // enable destructuring
@sultaniman
sultaniman / bobp-python.md
Created November 8, 2015 15:21 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@sultaniman
sultaniman / ember-tip-1.js
Created June 10, 2016 14:43
Ember shorthand for Ember.get
import Ember from 'ember';
const {get} = Ember;
export default Ember.Component.extend({
_doSomething() {
let getSomething = get(this, 'something');
}
});
@sultaniman
sultaniman / ember-tip-1-1.js
Last active June 10, 2016 15:04
prop function
import Ember from 'ember';
const {on, get} = Ember;
let prop = function(key) { return get(this, key) };
export default Ember.Component.extend({
onElementInsert: on('didInsertElement', function() {
// In this place we just bind components context
import Ember from 'ember';
const {on, get} = Ember;
let make = () => function(key) { return get(this, key) };
let prop = make();
export default Ember.Component.extend({
onElementInsert: on('didInsertElement', function() {
@sultaniman
sultaniman / escape.html.es6
Created November 8, 2016 13:40
Sanitize HTML inspired by Ember
const escape = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
// jscs:disable
"'": '&#x27;',
// jscs:enable
'`': '&#x60;',
'=': '&#x3D;'
/*
* Wraps axios and provides
* more convenient post method
* calls with payload data
*/
export function post(uri, data) {
return axios.post(uri, data, {
headers: getHeaders(),
withCredentials: true
})
/*
* Returns default headers list
* which will be used with every request.
*/
function getHeaders(multipart = false) {
let defaultHeaders = BASE_HEADERS
if (multipart) {
defaultHeaders = {}
}