Skip to content

Instantly share code, notes, and snippets.

@alik472
alik472 / decorators.py
Last active April 6, 2018 12:44
Python Decorators
def mydec(func):
def wrapper(*args,**kwargs):
print('before')
result=func(*args,**kwargs)
print('after')
return result
return wrapper
@alik472
alik472 / test1.js
Last active May 3, 2019 18:42
JS Days - Part 1
function b(){
console.log("Called b!")
}
// b();
// console.log(a);
var a='var a';
@alik472
alik472 / this.js
Created May 6, 2019 10:41
JS Days - Part 2 - this in different contexts
function b(){
var myVar='b'
// console.log(this)
console.log(this.myVar,'this.myVar')
console.log(myVar,'myVar')
}
var myVar='a'
console.log(this.myVar,'this.myVar')
b()
@alik472
alik472 / scope.js
Last active May 6, 2019 13:38
JS days - Part 3 - Scope Chain
function b (){
// reference outer environment
console.log(myVar, 'myVar inside function b')
}
function a(){
var myVar=2
console.log(this===global)
console.log(myVar,'myVar inside function a')
console.log(this.myVar,'this.myVar inside function a')
@alik472
alik472 / forloop.js
Last active May 15, 2019 14:07
JS Days - Part 4 - for loops (for of/ for in/ forEach)
var myobj=['a','b','c']
for (var x in myobj){console.log(x)}
// 0
// 1
// 2
for (var x of myobj){console.log(x)}
// a
// b
@alik472
alik472 / thread.py
Created May 18, 2019 11:55
Derek Banas threading code
# https://youtu.be/Bs7vPNbB9JM
# When you use threads it is like you are running
# multiple programs at once.
# Threads actually take turns executing. While one
# executes the other sleeps until it is its turn
# to execute.
import threading
import time
@alik472
alik472 / lambda.py
Created May 18, 2019 13:41
Derek Banas Python lambda/map/reduce/anynumous funcs/etc
# ---------- FUNCTIONS AS OBJECTS ----------
def mult_by_2(num):
return num * 2
# A function can be
# 1. Assigned to another name
times_two = mult_by_2
@alik472
alik472 / js.md
Created May 19, 2019 18:51
JS Days Part 5 - object methods iterations

-Object properties can be own (the property is on the object itself) or inherited (not on the object itself, on one of its prototypes).

-Object properties can be enumerable or non-enumerable. Non-enumerable properties are left out of lots of property enumerations/arrays.

-Property names can be strings or Symbols. Properties whose names are Symbols are left out of lots of property enumerations/arrays.

-Here in 2018, your options for looping through an object's properties are (some examples follow the list):

  1. for-in [MDN, spec] — A loop structure that loops through the names of an object's enumerable properties, including inherited ones, whose names are strings
@alik472
alik472 / to-dict.py
Created May 23, 2019 09:52
sqlalchemy to dic
def toDict(self):
return { c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs }
@alik472
alik472 / Database.js
Created July 19, 2019 20:11
Node mysql promise lib
const util = require('util')
const mysql = require('mysql')
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'root',
password: 'password',
database: 'my_database'
})