This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Prints 'here', first, then roughly less than 1000 ms later, prints a b c d. | |
* For each element in the array, a setTimeout callback is set up, but since there's a 1000 ms delay, that function isn't | |
* called yet. The forEach won't block on any of these callback setups, so it skips through and prints 'here' first. | |
*/ | |
function ex1() { | |
var arr = ['a', 'b', 'c', 'd']; | |
arr.forEach(function(e) { | |
setTimeout(function() { | |
console.log(e); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# NOTE: numpy uses radians for its angles | |
# constants | |
PI = np.pi | |
cos = lambda ang: np.cos(ang) | |
ncos = lambda ang: -1*np.cos(ang) | |
sin = lambda ang: np.sin(ang) | |
nsin = lambda ang: -1*np.sin(ang) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
There is a button in each UICVCell, and we want to pass data based on a specific cell when we segue. | |
*/ | |
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
let destController = segue.destination as! CommentController | |
if let selectedFeedCell = (sender! as AnyObject).superview!?.superview as? FeedCell { | |
let indexPath = self.collectionView!.indexPath(for: selectedFeedCell)! | |
let row = indexPath.row | |
destController.feedItemInd = row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { | |
@IBOutlet weak var embeddedCV: UICollectionView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// make ourselves the delegate and data source of the CV. | |
embeddedCV.delegate = self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a=2; | |
var obj={a: 3}; | |
function getA() { return this.a; } | |
console.log(getA()); // 2 | |
var tmp=getA.bind(obj); | |
console.log(tmp()); // 3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import { connect } from 'react-redux'; | |
import './App.css'; | |
let nextTodoId = 0 | |
const addTodo = (text) => ({ | |
type: 'add', | |
id: nextTodoId++, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnionFind: | |
def __init__(self, N): | |
self.parent=[i for i in range(N+1)] | |
def findParent(self, v): | |
if self.parent[v]==v: return v | |
else: return self.findParent(self.parent[v]) | |
def union(self, v, w): | |
vp=self.findParent(v) | |
wp=self.findParent(w) | |
self.parent[vp]=wp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnionFind { | |
public: | |
vector<int> parent; | |
int getParent(int v) { | |
if (parent[v]==v) return v; | |
return getParent(parent[v]); | |
} | |
void unionn(int v, int w) { | |
int vp=getParent(v); | |
int wp=getParent(w); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CallApplyBind examples, cuz i occassionally forget call and apply | |
function fn(x,y) { | |
return x+y+this.z | |
} | |
var obj={ z: 4 }; | |
var objfn=fn.bind(obj); |
OlderNewer