Skip to content

Instantly share code, notes, and snippets.

BetterProgramming

Block or report user

Report or block BetterProgramming

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fs.js
const fs = require("fs");
const file = "./files/file.txt";
fs.chown(file, 1000, 1000, err => {
if (err) throw err;
console.log("File ownership changed");
});
View specify_interface_type.ts
interface EchoFn<T> {
<T>(a: T): T;
};
function echo<T>(a: T): T {
return a;
}
const e: EchoFn<number> = echo;
View signature_in_interface.ts
interface EchoFn {
<T>(a: T): T;
};
function echo<T>(a: T): T {
return a;
}
const e: EchoFn = echo;
View generic_regular.ts
interface EchoInterface {
[prop: string]: any
}
function echo<T, U, V, W>(a: T, b: U, c: V, d: W): EchoInterface {
return {a,b,c,d};
}
console.log(echo(1, 'a', false, {}));
View location_types.py
# Plot location_types
df = pd.DataFrame.from_dict(r['location_types'], orient='index')
df.index.name = 'location'
df.reset_index(inplace=True)
df.rename(columns={0: 'val'}, inplace=True)
# Remove the row with point_of_interest and establishment location
df = df[(df.location != 'point_of_interest') & (df.location != 'establishment')]
plt.figure(figsize=(16, 11))
sns.barplot(x="location", y="val", data=df, order=df.sort_values(
'val', ascending=False)['location']).set_title('Location types from {}'.format(location))
View PlacesVisualize.py
import argparse
import time
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from places_summarized import Client
parser = argparse.ArgumentParser()
parser.add_argument('--key', '-K',
help="Google Maps API key", type=str, default='')
parser.add_argument('--location', '-L',
View FakeClient.py
import pprint
from places_summarized.fake_client import FakeClient
pp = pprint.PrettyPrinter(indent=4)
fclient = FakeClient()
summary = fclient.places_summary()
pp.pprint(summary.result())
View summary_1.py
client = Client(key=key)
summary = client.places_summary(location=location, radius=radius)
# Get more results!
for _ in range(4):
print(summary.nearby_results)
time.sleep(5)
client.get_more_results(summary)
r = summary.result()
View thing6.js
class ShapeCalculator {
constructor() {
this.box = new Box();
}
getBoxSurfaceArea() {
return this.box.getArea();
}
getBoxVolume() {
return this.box.getBoxVolume();
}
View thing5.js
class Box {
constructor() {
this.length = 1;
this.width = 1;
this.height = 1;
}
getSurfaceArea() {
return 2 * (this.height * this.width) + 2 * (this.height * this.length) + 2 * (this.length * this.width)
}
getBoxVolume() {
You can’t perform that action at this time.