Skip to content

Instantly share code, notes, and snippets.

View angel-vladov's full-sized avatar

Angel Vladov angel-vladov

View GitHub Profile
@angel-vladov
angel-vladov / onBeforePrint.js
Last active May 10, 2018 12:18
AngularJS 1 on before print directive
/**
* AngularJS example directive.
* Allows you to modify the page DOM and CSS styles before printing by exexuting the passed expression.
* Will force a $digest phase before the print operation.
*
* Example: <div ng-class="{printed: isPrinted}" on-before-print="printed = true" />
*/
module.directive('onBeforePrint', ['$window', '$rootScope', '$timeout', function onBeforePrint($window, $rootScope, $timeout) {
var beforePrintDirty = false;
var listeners = [];
@angel-vladov
angel-vladov / Sublime-eclipse-keymap.json
Last active January 4, 2016 14:18
Eclipse Keybindings for Sublime Text 2
[
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "Packages/Default/Add Line.sublime-macro"} },
{ "keys": ["alt+up"], "command": "swap_line_up" },
{ "keys": ["alt+down"], "command": "swap_line_down" },
{ "keys": ["ctrl+alt+j"], "command": "join_lines" },
{ "keys": ["ctrl+alt+down"], "command": "duplicate_line" },
{ "keys": ["shift+ctrl+r"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
{ "keys": ["ctrl+shift+s"], "command": "save_all" },
{ "keys": ["ctrl+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
{ "keys": ["shift+ctrl+f4"], "command": "close_all" },
@angel-vladov
angel-vladov / Greasemonkey-jq-boilerplate.js
Created January 28, 2014 12:00
Boilerplate code for a Greasemonkey script which reuses the jQuery from the page it's attached to.
var jQuery, $ = null;
function addJQuery(callback) {
var p = null;
if(window.opera || window.navigator.vendor.match(/Google/)) {
var div = document.createElement("div");
div.setAttribute("onclick", "return window;");
p = div.onclick();
}
@angel-vladov
angel-vladov / powershell-net.ps1
Last active January 9, 2024 15:41
PowerShell function you can use for reading UTF8 encoded HTML pages content. The built in Invoke-WebRequest and Invoke-RestMethod fail miserably.
function Read-HtmlPage {
param ([Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)][String] $Uri)
# Invoke-WebRequest and Invoke-RestMethod can't work properly with UTF-8 Response so we need to do things this way.
[Net.HttpWebRequest]$WebRequest = [Net.WebRequest]::Create($Uri)
[Net.HttpWebResponse]$WebResponse = $WebRequest.GetResponse()
$Reader = New-Object IO.StreamReader($WebResponse.GetResponseStream())
$Response = $Reader.ReadToEnd()
$Reader.Close()
@angel-vladov
angel-vladov / soundjs-cordova.js
Created April 9, 2016 23:04
Using createjs WebAudioPlugin with Phonegap (Cordova)
(function() {
'use strict';
var XHRRequest = createjs.XHRRequest;
var XHRRequest_checkError = XHRRequest.prototype._checkError;
XHRRequest.prototype._checkError = function () {
// Override of version 0.62 implementation
if ('cordova' in window) {
@angel-vladov
angel-vladov / cordova_stream_ring.js
Last active July 21, 2016 07:36
Cordova hook for ringer volume controled Media on Android
#!/usr/bin/env node
// Changes your app to use STREAM_RING instead of STREAM_MEDIA
// v1.0
// Install mkdirp before using this hook. Run npm install mkdirp --save
// Place this file in hooks/after-prepare
// This hook will change AudioManager.STREAM_MUSIC to AudioManager.STREAM_RING
var fs = require('fs');
var path = require('path');
@angel-vladov
angel-vladov / crosswalk-no-ssl-error.js
Last active August 31, 2016 14:55
Cordova hook that disables Crosswalk SSL error checks. Otherwise HTTPS doesn't work with Android 5.
#!/usr/bin/env node
// Disables crosswalk release time SSL errors check
// v1.0
// Install mkdirp before using this hook. Run npm install mkdirp --save
// Place this file in hooks/after-prepare
// Confirmed working with Crosswalk 1.7.2
var fs = require('fs');
var path = require('path');
@angel-vladov
angel-vladov / jquery-plugin-example.js
Last active December 6, 2016 11:35
jQuery prototypical plugin example
// globals jQuery
(function ($) {
'use strict';
// TODO: Replace pluginExample and PluginExample with your plugin name
$.fn.pluginExample = function (option/*, varArgs*/) {
var args = Array.prototype.slice.call(arguments, 1);
return this.each(function () {
var $element = $(this);
@angel-vladov
angel-vladov / select2-bootstrap4.after.scss
Last active March 16, 2018 16:01
Select2 for Bootstrap4
// Import this file after select2 bootstrap theme. Content won't be centered if you don't include this file.
.select2-container--bootstrap {
.select2-selection--multiple {
.select2-selection__choice {
margin-top: calc(#{$s2bs-padding-base-vertical} - 1px);
}
.select2-search--inline .select2-search__field {
height: $s2bs-input-height-base;
}
@angel-vladov
angel-vladov / .bash_profile
Last active August 29, 2018 10:05
Mac OS terminal prompt with git branch
export PATH="/usr/local/bin:$PATH"
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1='\[\033[32m\]' # change to green
PS1="$PS1"'\u@\h ' # user@host<space>