Skip to content

Instantly share code, notes, and snippets.

View santiago-puchginer-snkeos's full-sized avatar
👨‍💻

Santi Puch Giner santiago-puchginer-snkeos

👨‍💻
  • SnkeOS
  • Munich
View GitHub Profile
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / func_decorator.py
Created May 28, 2017 16:33
Function decorator in Python
import time
""" FUNCTION DECORATOR """
def log_function(time_it=False):
def decorate(func):
def wrapper(*args, **kwargs):
print('LOGGING :: Start function {}'.format(func.__name__))
if time_it:
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / class_decorator.py
Created May 28, 2017 16:27
Class-based Python decorators
import time
""" EXAMPLE LOGGING DECORATOR """
class log_function(object):
def __init__(self, time_it=False):
self.time_it = time_it
def __call__(self, func, *args, **kwargs):

Multi-process architecture

  • Main process: in charge of creating web pages by creating BrowserWindow instances. Manages all web pages and their corresponding renderer process
  • Renderer process: process assigned to each web page to be rendered. Runs a BrowserWindow instance (previously created by the main process). ATTENTION: it can't manage GUI resources itself, instead it must communicate with the main process to request that the main process performs those operations, for example using the remote module (for RPC style communication).

Browser Window

Class that gives you the ability to create a browser window. It inherits from EventEmitter. In the main process: const BrowserWindow = require('electron').BrowserWindow; In a renderer process: const BrowserWindow = require('electron').remote.BrowserWindow;

@santiago-puchginer-snkeos
santiago-puchginer-snkeos / prototype_inheritance.js
Created May 5, 2016 22:25
Prototype inheritance in Javascript
// Snippet showing inheritance through prototypes
var Animal = function(type){
this.type = type;
};
Animal.prototype.eat = function(){
console.log("They eat food to survive.");
};
var Mammal = function(){};
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / closure.js
Created May 5, 2016 22:23
Closures in Javascript
// Snippet for closures
// A closure is a special kind of object that combines two things: a function,
// and the environment in which that function was created
function Person(name) {
var _name = name; // Private variable name
this.getName = function() {
return _name;
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / currying.js
Created May 5, 2016 22:22
Currying in Javascript
// Snippet for currying
// Currying can be described as transforming a function that takes N arguments
// so that it can be called as a chain of N functions each taking a single argument.
let greetings = from =>
message =>
recipient =>
'Dear ${recipient},\n\t${message}\n${from}.';
let person = greetings("Jerry");
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / template_str_es6.js
Created May 5, 2016 22:22
Template string in Javascript (ES6)
// Snippet for template strings (ES6)
let firstName = "Santi";
let lastName = "Puch";
// Instead of doing this...
console.log("My name is " + firstName + " " + lastName);
// Use this...
console.log(`My name is ${firstName} ${lastName}`);
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / iife.js
Created May 5, 2016 22:21
Immediately Invoked Function Expression in Javascript
// Snippet for IIFE
// An IIFE (Immediately Invoked Function Expression) is a JavaScript function
// that runs as soon as it is defined. They can be written in different ways,
// though a common convention is to enclose both the function expression and
// invocation in parentheses.
var sulphuricAcid = (function(){
var corrosive = true;
var pH = 2;
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / arrow_functions_es6.js
Created May 5, 2016 22:19
Arrow functions in Javascript (ES6)
// Snippet for arrow functions (ES6)
// Example of a normal arrow function
let substract = (a, b) => {
return a - b;
}
// Example of a one-line arrow function
let add = (a, b) => a + b;
@santiago-puchginer-snkeos
santiago-puchginer-snkeos / rest_spread_es6.js
Created May 5, 2016 22:17
Rest parameters and spread operator in Javascript (ES6)
// Snippet for rest parameters and spread operator (ES6)
// Rest parameters allow you to capture and indefinite number of parameters
// passed to a function
let sum = function(...args) {
// args is an Array with the parameters
return args.reduce( (prev, curr) => prev + curr);
}
console.log(sum(1, 1, 1, 1, 3)) // 7