Skip to content

Instantly share code, notes, and snippets.

View sayinserdar's full-sized avatar
🏃‍♂️

Serdar Sayin sayinserdar

🏃‍♂️
View GitHub Profile
@sayinserdar
sayinserdar / pdfDownloader.py
Created March 12, 2018 09:27
Tiny python script for downloading pdf file through web site link
from bs4 import BeautifulSoup
import urllib.request
import requests
import os
with urllib.request.urlopen('Your URL') as response:
html_doc = response.read()
def download_file(url):
local_filename = url.split('/')[-1]
@sayinserdar
sayinserdar / short-circuiting .js
Last active February 20, 2021 15:09
Short circuiting in JS
let a; // falsy value
let b = predefinedFunctionWhichReturnsFalse(); // false
let c = computationallyHeavyFunctionWhichReturnsFalse(); // falsy value
let d = false;
let e = true;
// Needs to evalaute every condition.
let result = a | b | c | d | e;
@sayinserdar
sayinserdar / template-conditions.ts
Last active February 22, 2021 13:38
Template Conditions in Angular
public user = await asyncUserFunction();
public cat = await asyncCatFunction();
public isCatVisible = user.cat.id === cat.id;
@sayinserdar
sayinserdar / component.html
Last active February 25, 2021 09:52
Template conditions
// Vague conditions that need investigating ❌
<div> *ngIf="user?.cat.id === cat?.id;"
Cute cat pictures need to be seen by that user.
</div>
// You can understand from naming and simpler expressions ✅
<div> *ngIf="isCatVisible"
Cute cat pictures need to be seen by that user.
@sayinserdar
sayinserdar / tsconfig.json
Created February 20, 2021 19:06
Tsconfig with paths
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
@sayinserdar
sayinserdar / spread.js
Last active June 24, 2021 16:32
Spread operator
// Can be used instead of Array functions
const a = [1,2,4];
const b = [3,7,6];
const c = 1;
// a.concat(b);
let arr = [...a,...b];
// Unshift, push
@sayinserdar
sayinserdar / arrow.js
Last active February 22, 2021 13:13
Arrow functions
// Example is from = https://www.javascripttutorial.net/es6/javascript-arrow-function/
// Normal/Traditional function
function Car() {
this.speed = 0;
this.speedUp = function (speed) {
this.speed = speed;
let self = this;
// Creates it's own scope. You have to create another variable to access the upper scope
// ❌
<div *ngIf="condition; else elseBlock">
<div class="cool-content">My beautiful styled content</div>
</div>
<ng-template #elseBlock>
<div>Same content but not cool </div>
</ng-template>
<div [class.cool-content]="condition">My beautiful styled content with nicer syntax</div>