Skip to content

Instantly share code, notes, and snippets.

@emrecamasuvi
emrecamasuvi / MapsResolver.js
Created August 8, 2022 07:45
Google Maps autocomplete resolver module
export class MapsResolver {
constructor(domEl, changeEventNamespace) {
this.input = domEl
this.changeEventNamespace = changeEventNamespace
this.loadMapsAPI()
window.initMap = this.listenMapEvents.bind(this)
}
loadMapsAPI() {
if (window.google && window.google.maps) return
// original code: https://github.com/AnthumChris/fetch-progress-indicators
const element = document.getElementById('progress');
fetch('url')
.then(response => {
if (!response.ok) {
throw Error(response.status+' '+response.statusText)
}
@emrecamasuvi
emrecamasuvi / keybindings.json
Created November 30, 2018 07:35
vs code keybindings.json
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+alt+enter",
"command": "editor.emmet.action.wrapWithAbbreviation"
},
{
"key": "ctrl+shift+oem_2",
"command": "editor.action.blockComment",
"when": "editorFocus"

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@emrecamasuvi
emrecamasuvi / api-cheatsheet-array.md
Created April 2, 2018 21:31 — forked from rauschma/api-cheatsheet-array.md
Array cheatsheet js javascript

Array<T>

Legend:

  • ✏️ method changes this.
  • 🔒 method does not change this.

Array<T>.prototype.*:

  • concat(...items: Array: T[] 🔒 ES3
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@emrecamasuvi
emrecamasuvi / js-javascript-snippets.js
Last active October 19, 2021 07:04
#js #javascript #snippets
// random numbergenerator between 0 and 1
var randomNum = ((Math.random() * 2) | 0) + 1 - 1;
// same memoize function from before
const memoize = (fn) => {
let cache = {};
return (...args) => {
let n = args[0];
if (n in cache) {
console.log('Fetching from cache', n);
@emrecamasuvi
emrecamasuvi / python sql n00b snippets
Last active May 29, 2018 19:34
python sql n00b tips snippets
python
>>> import urllib2
>>> p = urllib2.urlopen("http://www.google.com")
>>> c = p.read()
>>> c
>>> dir(p)
>>> exx = p.geturl()
>>> exx
'http://www.google.com.tr/?gfe_rd=cr&ei=77OxVof4Hqyo8we8qoyADw'
>>> p.headers.items()
@emrecamasuvi
emrecamasuvi / terminal git cmd bash etc
Last active November 6, 2020 08:08
terminal git cmd bash etc
# To recursively give directories read&execute privileges:
find /path/to/base/dir -type d -exec chmod 755 {} +
# To recursively give files read privileges:
find /path/to/base/dir -type f -exec chmod 644 {} +
# Or, if there are many objects to process:
chmod 755 $(find /path/to/base/dir -type d)
chmod 644 $(find /path/to/base/dir -type f)
@emrecamasuvi
emrecamasuvi / scss-css.css
Last active January 29, 2024 10:14
sass, scss, css snippets; some useful stuff
// mobile viewport bug with `100vh` in WebKit (iOS Safari)!
// credits: https://twitter.com/AllThingsSmitty/status/1254151507412496384
body {
min-height: 100vh;
min-height: -webkit-fill-available;
}
html:focus-within {
scroll-behavior: smooth;
}