Skip to content

Instantly share code, notes, and snippets.

@alik472
alik472 / cron.js
Created March 30, 2023 07:50
cron.js
const { XMLParser, XMLBuilder, XMLValidator } = require("fast-xml-parser");
const axios = require('axios')
const cheerio = require('cheerio');
axios.post("https://www.besoccer.com/rss_en.xml").then(data => {
const parser = new XMLParser();
let xml = parser.parse(data.data);
const readyData = xml.rss.channel.item
// title/link/guid/pubDate/author/description/content:encoded
@alik472
alik472 / directory_all_files_uppercase.py
Created June 26, 2020 10:28
Rename all files to uppercase
import os
files = os.listdir('.')
for f in files:
newname = f.upper()
if newname == f:
continue
if newname in files:
print( "error: %s already exists" % newname )
os.rename(f, newname)
import os
from PIL import Image
files = os.listdir('.')
for f in files:
first_name = (f[:6])
last_name = (f[-4:])
jpg_name = '.PNG'
full_name = first_name + last_name
try:
@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'
})
@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 / 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 / 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 / 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 / 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 / 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')