Skip to content

Instantly share code, notes, and snippets.

View pcote's full-sized avatar
🏠
Working from home

Emma Cote pcote

🏠
Working from home
View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<title>AngularJS looping example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body>
<div ng-app="app" ng-controller="controller">
$(function(){
var json_args = {
num1: 5,
num2: 3
};
var showResult = function(res){
alert(res.sum);
};
var controller = function($http){
var json_args = {
num1: 5,
num2: 3
};
var showResult = function(res){
alert(res.data.sum);
}
<!-- This component is embedded into the template html
of the 'mainApp' component.-->
<aps-search-results results="mc.searchResults"></aps-search-results>
@pcote
pcote / apsSearchResultsDirective.js
Created August 7, 2016 13:51
Example directive from AptPackageShow Project
var apsSearchResults = function(){
var d = {};
d.restrict = "E";
d.scope = {
results: "="
};
d.templateUrl = "searchresults/searchresults.html";
d.controller = "searchResultsController";
d.controllerAs = "src";
@pcote
pcote / check_output.py
Created August 7, 2016 13:46
Example of check_output function from subprocess where shell gets used.
from subprocess import check_output
command_str = "/usr/bin/apt-cache stats"
raw_results = check_output(command_str, shell=True)
tupled_result_list = [tuple(result.split(" - ")[:2])
for result in result_list
if result]
import re
def image_format(file_name):
raw_data = open(file_name, "rb").read()
ascii_data = raw_data.decode("ascii", errors="ignore")
for result in re.finditer(r"\w+", ascii_data):
word = result.group()
return word
var googleDirective = function(){
var d = {};
d.restrict = "E";
d.link = function(scope, elem, attrs){
var textBody = elem.html();
var url = "http://www.google.com/search?q=" + escape(textBody)
var searchTag = "<a href='" + url + "'>" + textBody + "</a>";
elem.html(searchTag)
};
return d;