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/local/bin/python3 | |
from sys import argv | |
from os import makedirs, system, path | |
from json import loads | |
from urllib.request import urlopen, urlretrieve | |
from subprocess import Popen, PIPE | |
def ascript(cmd): | |
return Popen(['osascript', '-', '2', '2'], stdin=PIPE, stdout=PIPE, stderr=PIPE, encoding='utf-8').communicate(cmd) |
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
// const xmlDoc = new DOMParser().parseFromString(xmlString, 'text/xml'); | |
function xmlToJson(xml) { | |
const parseAll = s => (s && ((!isNaN(s) && parseFloat(s)) || (Date.parse(s) && new Date(s)))) || s.trim(); | |
const nodesToJson = function(nodes) { | |
return Array.from(nodes || []) | |
.map(item => ({ | |
name: item.nodeName, | |
value: item.nodeType === Node.ATTRIBUTE_NODE ? parseAll(item.nodeValue) : xmlToJson(item) | |
})) | |
.filter(item => item.value) |
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
function magicSquare(date) { | |
date = date instanceof Date ? date : new Date(date); | |
var d = date.getDate(), | |
m = date.getMonth() + 1, | |
c = ~~(date.getFullYear() / 100), | |
y = date.getFullYear() % 100; | |
return [ | |
[d, m, c, y], | |
[y + 1, c - 1, m - 3, d + 3], | |
[m - 2, d + 2, y + 2, c - 2], |
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 { coerceBooleanProperty } from '@angular/cdk/coercion'; | |
import { DOCUMENT } from '@angular/common'; | |
import { Directive, ElementRef, Inject, Input, OnInit } from '@angular/core'; | |
@Directive({ selector: '[myAutoFocus], [autofocus]' }) | |
export class AutoFocusDirective implements OnInit { | |
private host: HTMLElement; | |
private focused: Element; | |
private autoFocus = true; |
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 { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; | |
import { Injectable } from '@angular/core'; | |
import { Observable, throwError } from 'rxjs'; | |
import { catchError } from 'rxjs/operators'; | |
@Injectable() | |
export class RestInterceptor implements HttpInterceptor { | |
baseUrl: string; // base API url | |
token: string; // Initialize from login |
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 { Injectable } from '@angular/core'; | |
import { Http, RequestOptionsArgs, Response } from '@angular/http'; | |
import { Observable } from 'rxjs/Observable'; | |
@Injectable() | |
export class RestService { | |
baseUrl: string; // base API url | |
token: string; // Initialize from login | |
constructor(private http: Http) {} |
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
function safeGet(obj, props, defaultValue) { | |
if (typeof props === 'string') { | |
props = props.split('.'); | |
} | |
function safeGetByArray(obj, propsArray, defaultValue) { | |
if (obj === undefined || obj === null) { | |
return defaultValue; | |
} | |
if (propsArray.length === 0) { | |
return obj; |
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
public static class SqlConnectionExtensions { | |
public static SqlCommand CreateCommand(this SqlConnection connection, string cmdText, CommandType cmdType = CommandType.Text, params SqlParameter[] parameters) { | |
var cmd = connection.CreateCommand(); | |
cmd.CommandText = cmdText; | |
cmd.CommandType = cmdType; | |
if (parameters != null) | |
foreach (var parameter in parameters) | |
cmd.Parameters.Add(parameter); | |
return cmd; | |
} |
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
<style type="text/css"> | |
input, | |
select, | |
textarea { | |
font-size: 1rem; | |
padding: 5px 10px; | |
height: 35px; | |
border-radius: 4px; | |
border: 1px solid #bbb; | |
outline: none; |
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
function ajax(method, url) { | |
var x = (function () { | |
return window.XMLHttpRequest | |
? new XMLHttpRequest() | |
: window.ActiveXObject | |
? new ActiveXObject("Microsoft.XMLHTTP") | |
: null; | |
})(); | |
x.open(method, url, true); |
NewerOlder