Skip to content

Instantly share code, notes, and snippets.

@caub
caub / .inputrc
Last active March 29, 2024 07:41
.inputrc
$include /etc/inputrc
# may need export INPUTRC=~/.inputrc note: use ctrl+v to debug readline
# set echo-control-characters off
set show-all-if-ambiguous on
# set history-preserve-point on
"\e[5~": beginning-of-history
@caub
caub / KRLS plot.md
Last active April 10, 2023 07:33
Santa-Fe regression with matlab

krls

nmse = 0.042

@caub
caub / pages_slash_404.js
Last active May 27, 2022 04:38
Next static
import React from 'react';
import Html from '../components/html'; // wraps pages into <html> and some common layout
// you might want a webpack.config.js at least for styles
// typically we use a sass loader, and also @emotion/react in our components
// Html will take care to add <link> for built ./build/**/*.css
// and <script> for built ./build/**/*.js if any, you might even inline it <script>{content}</script> if short
// It's also possible to build css/js assets per page, we didn't do that
export async function getServerSideProps({ req }) {
@caub
caub / api.js
Last active December 21, 2021 17:06
Simple fetch wrapper example for your API calls
function fetchJson(path, {method, body}) {
return fetch(`${API_BASE_URL}${path}`, {
method,
// credentials: 'include', // Use either 1. this if using cookies-based authentication
headers: {
// Authorization: `Bearer ${localStorage.getItem('access_token')}`, // or 2. if using access token authentication
...body && {'Content-Type': 'application/json'},
},
body: body && JSON.stringify(body)
}).then(async r => {
@caub
caub / zendesk-chat.js
Last active November 15, 2021 17:23
Zendesk Chat API
const http = require('http');
const fetch = require('node-fetch');
const getToken = () => new Promise((resolve, reject) => {
const server = http.createServer(async (req, res) => {
res.end();
const params = new URLSearchParams(req.url.slice(1));
console.log('rec', req.url, params);
if (params.has('code')) {
resolve(params.get('code'));
@caub
caub / svm.py
Last active October 31, 2021 22:31
Simplified SMO from coursera's ml-class converted from matlab
from scipy import *
#from scipy.linalg import *
from pylab import *
class SVM:
def train(self, X, Y, kernel, C, tol = 1e-3, max_passes = 5):
m = size(X, 0)
n = size(X, 1)
@caub
caub / api.js
Last active October 28, 2021 18:18
Simple fetch wrapper
const API_URL = 'https://..'; // Your API base url
// returns true for plain object literals, like {foo: 'bar'}, false for other cases, like instances of classes, like lodash.isPlainObject
const isPlainObject = obj => obj && Object.getPrototypeOf(obj) === Object.prototype || Object.getPrototypeOf(obj) === null;
export function fetchJson(url, { body, headers, ...o } = {}) {
const isJson = isPlainObject(body); // most of the time we send plain 'json' objects
return fetch(url[0] === '/' ? API_URL + url : url, {
headers: {
...isJson && {'Content-Type': 'application/json'},
@caub
caub / webpack.config.js
Last active June 6, 2021 17:17
react-scripts lite
require('dotenv/config');
const fs = require('fs-extra');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
fs.emptyDirSync(__dirname + '/build');
fs.copySync(__dirname + '/public/', __dirname + '/build/', {
dereference: true,
@caub
caub / sublimetext.md
Last active April 15, 2021 19:31
VSCode's Format on save for SublimeText

requirement: TypeScript package should be installed

Step 1: Create a new plugin (Tools > Developer > new plugin) with the following, save it as format-on-save.py for example:

import sublime
import sublime_plugin

class FormatTypescriptOnSave(sublime_plugin.EventListener):
  def on_pre_save(self, view): 

Double vs Single quotes for JavaScript Strings

"foo"

  • Newcomers will already be familiar with double quotes from their language. In English, we must use double quotes " to identify a passage of quoted text. If we were to use a single quote ', the reader may misinterpret it as a contraction. The other meaning of a passage of text surrounded by the ' indicates the 'colloquial' meaning. It makes sense to stay consistent with pre-existing languages, and this may likely ease the learning and interpretation of code.
  • Double quotes eliminate the need to escape apostrophes (as in contraptions). Consider the string: "I'm going to the mall", vs. the otherwise escaped version: 'I'm going to the mall'.
  • Double quotes mean a string. When you learn a new language like Java, Python, or C, double quotes are always used. This is because, as mentioned above, double quotes have always been used in language to indicate quoted passages of text. Old books will use double quo