This is a collection of my most often used lines of code, as well as a few other examples I want to have ready at a moment's notice. These snippets focus on building HTML from scratch, linking in good web fonts, and setting up responsive styles for your pages.
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
.text-xs-left { text-align: left; } | |
.text-xs-right { text-align: right; } | |
.text-xs-center { text-align: center; } | |
.text-xs-justify { text-align: justify; } | |
@media (min-width: @screen-sm-min) { | |
.text-sm-left { text-align: left; } | |
.text-sm-right { text-align: right; } | |
.text-sm-center { text-align: center; } | |
.text-sm-justify { text-align: justify; } |
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
"""Extract metadata from Project Gutenberg RDF catalog into a Python dict. | |
Based on https://bitbucket.org/c-w/gutenberg/ | |
>>> md = readmetadata() | |
>>> md[123] | |
{'LCC': {'PS'}, | |
'author': u'Burroughs, Edgar Rice', | |
'authoryearofbirth': 1875, | |
'authoryearofdeath': 1950, |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<script type="module"> | |
import { h, text, app } from "https://unpkg.com/hyperapp" | |
app({ | |
init: () => 0, | |
view: state => | |
h("main", {}, [ |
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
[Unit] | |
Description="frappe-bench-frappe-default-worker" | |
PartOf=frappe-bench-workers.target | |
[Service] | |
User=revant | |
Group=revant | |
Restart=always | |
ExecStart=/home/revant/.local/bin/bench worker --queue default | |
StandardOutput=file:/home/revant/frappe-bench/logs/worker.log |
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
# Implementation of a simple MLP network with one hidden layer. Tested on the iris data set. | |
# Requires: numpy, sklearn>=0.18.1, tensorflow>=1.0 | |
# NOTE: In order to make the code simple, we rewrite x * W_1 + b_1 = x' * W_1' | |
# where x' = [x | 1] and W_1' is the matrix W_1 appended with a new row with elements b_1's. | |
# Similarly, for h * W_2 + b_2 | |
import tensorflow as tf | |
import numpy as np | |
from sklearn import datasets | |
from sklearn.model_selection import train_test_split |
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 os | |
import platform | |
if os.name == 'nt' and platform.release() == '10' and platform.version() >= '10.0.14393': | |
# Fix ANSI color in Windows 10 version 10.0.14393 (Windows Anniversary Update) | |
import ctypes | |
kernel32 = ctypes.windll.kernel32 | |
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7) |
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
# Helper function to plot a decision boundary. | |
# If you don't fully understand this function don't worry, it just generates the contour plot below. | |
def plot_decision_boundary(pred_func): | |
# Set min and max values and give it some padding | |
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5 | |
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5 | |
h = 0.01 | |
# Generate a grid of points with distance h between them | |
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h)) | |
# Predict the function value for the whole gid |
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
#!/usr/bin/env python | |
"""Compare two aligned images of the same size. | |
Usage: python compare.py first-image second-image | |
""" | |
import sys | |
from scipy.misc import imread | |
from scipy.linalg import norm |
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import tweepy #https://github.com/tweepy/tweepy | |
import csv | |
import sys | |
#Twitter API credentials | |
consumer_key = "" | |
consumer_secret = "" |
OlderNewer