Skip to content

Instantly share code, notes, and snippets.

@andreisoriga
andreisoriga / mqtt_client.js
Created August 9, 2018 12:30
MQTT.js client implementation
// https://github.com/mqttjs/MQTT.js
// https://gist.github.com/learncodeacademy/3a96aa1226c769adba39
let mqtt = require('mqtt');
let client = mqtt.connect('mqtt://localhost');
const subscriberList = ['info', 'actions'];
client.on('connect', () => {
console.log(`Subscribing to: ${subscriberList}`);
@andreisoriga
andreisoriga / python_source_install.md
Last active July 11, 2018 07:26
Install Python from sources on Linux

Linux:

Install some package dependencies

./configure --enable-shared --enable-optimizations --prefix=/usr/local LDFLAGS="-Wl,--rpath=/usr/local/lib"

make

sudo make install
@andreisoriga
andreisoriga / lambdas.py
Created December 28, 2015 14:02
Common lambda functions
# square
sq = lambda x: x * x
sq(99) # 9801
# sum rgb
rgb = lambda r, g, b: r + g + b
rgb(45, 22, 35) # 102
# remove duplicate values from iterable
remove_duplicates = lambda iterable: list(set(iterable))
@andreisoriga
andreisoriga / generators.py
Created December 28, 2015 14:01
Generators
# return a generator instead of a list
def interesting_lines(file):
for fline in file:
fline = fline.strip()
if fline.startswith('#'):
continue
if not fline:
continue
yield fline
@andreisoriga
andreisoriga / 30_minutes_generator.py
Created December 28, 2015 08:22
30 Minutes Generator
import datetime
import itertools
# it generates dates in 30 minutes intervals
date_generator = (datetime.datetime.today() - datetime.timedelta(minutes=i) for i in itertools.count(0, 30))
# it gets 24h of data
dates = itertools.islice(date_generator, 24 * 2)
# convert generator data in list
@andreisoriga
andreisoriga / OrderedDict.py
Last active February 20, 2017 04:39
Data Structures and Algorithms
# Keeping Dictionaries in Order
from collections import OrderedDict
d = OrderedDict()
d['foo'] = 1
d['bar'] = 2
d['spam'] = 3
d['grok'] = 4
# Outputs "foo 1", "bar 2", "spam 3", "grok 4"
@andreisoriga
andreisoriga / style.less
Last active December 28, 2015 07:36
css: template
// font definitions
@font-open: 'Open Sans', sans-serif;
// color definitions
@color-bg: white;
@color-font: #333;
@color-link: #1570be;
/**
* Here I define the base style and make rewrites
@andreisoriga
andreisoriga / style.css
Last active December 28, 2015 07:35
css: Start Template
body {
/* background style */
background-color:#f6f6f6;
/* typo style */
font-family: 'Oxygen', arial, sans-serif;
line-height: 18px;
font-size: 13px;
color: #343434;
}
@andreisoriga
andreisoriga / gitrepo.git
Last active December 28, 2015 07:25
Create Dropbox Git Repo
Create Dropbox Git Repo
$ cd ~/Dropbox
$ mkdir -p repos/your-repo-name
$ git init –-bare repos/your-repo-name
Initialized empty Git repository in /Users/xxxxxx/Dropbox/repos/your-repo-name/
$ cd ~/ProjectFolder
$ git init .
Initialized empty Git repository in /Users/xxxxx/ProjectFolder/
@andreisoriga
andreisoriga / styles.css
Last active December 28, 2015 07:36
CSS3 styles
/* shadow */
-moz-box-shadow:0 0 7px rgba(0, 0, 0, 0.4);
-webkit-box-shadow:0 0 7px rgba(0, 0, 0, 0.4);
box-shadow:0 0 7px rgba(0, 0, 0, 0.4);
/* border radius */
-moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px;
/* inset shadow */
-moz-box-shadow: inset 0 0 7px rgba(0, 0, 0, 0.4);