Skip to content

Instantly share code, notes, and snippets.

View psycalc's full-sized avatar
💭
DevOps Learning

Raziel psycalc

💭
DevOps Learning
View GitHub Profile
@psycalc
psycalc / powershell.ps1
Created May 10, 2016 18:15
Add signature to ps file
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")>Out-Null
Add-Type -AssemblyName PresentationCore
$Clipboard=[Windows.Clipboard]::GetText()
$Clipboard = $Clipboard -Replace '"', ""
#[System.Windows.Forms.MessageBox]::Show("Clipboard: " + $Clipboard)
$Pattern = "^[a-z]:\\[a-z\\_\s0-9\(\)]*\.exe"
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")>Out-Null
Add-Type -AssemblyName system.Windows.Forms
#Если буфер обмена соответсвует шаблону, то не открываем диалоговое окно
If ($Clipboard -imatch $Pattern) {
@psycalc
psycalc / audiocookies.js
Created May 16, 2016 11:21
setCookies js function
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
@psycalc
psycalc / audiocookies.js
Created May 16, 2016 11:22
function getCookies js
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";"); /*куки храняться через точку с запятой*/
for (i=0;i<ARRcookies.length;i++)/*проходим по массиву кукиес*/
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
@psycalc
psycalc / audiocookies.js
Created May 16, 2016 12:51
!!!!!сurrentTime = 0
firsttagaudio.src=currentSong; /*!!!!!!!!! Если устанавливаем новый источник музыки новый mp3 файл к примеру позиция воспроизведения сбрасываеться на 0*/
@psycalc
psycalc / NewProject.ps1
Created May 25, 2016 13:56
front-end evnironment script
#1) Итак сначала читаем с клавиатуры название проекта
$ProjectName=Read-Host -Prompt 'Input project name'
#... описание проекта
$Description=Read-Host -Prompt 'Input project description'
#Cоздадим репозиторий
$AccessToken = '1' #Generated by github settings!
#Сервеная сторона
#Когда пользователь хочет отправить the server authentication credentials it may use the Authorization field.
#
#The Authorization field is constructed as follows:
# Перезапустить скрипт/консоль как администартор с параметрами
if(-not([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$Arguments = "& '" + $MyInvocation.MyCommand.Definition + "'"
Start-Process powershell -Verb RunAs -ArgumentList $Arguments
Break
}
@psycalc
psycalc / gist:9c894a4a0fdb1c3927a9617e496fc424
Created June 7, 2016 19:40
Get External Ip addresss PowerShell
# I am defining website url in a variable
$url = "http://checkip.dyndns.com"
# Creating a new .Net Object names a System.Net.Webclient
$webclient = New-Object System.Net.WebClient
# In this new webdownlader object we are telling $webclient to download the
# url $url
$Ip = $webclient.DownloadString($url)
# Just a simple text manuplation to get the ipadress form downloaded URL
# If you want to know what it contain try to see the variable $Ip
$Ip2 = $Ip.ToString()
@psycalc
psycalc / gist:9f82ee5ebc43b6243b4fd665555ea314
Last active July 20, 2016 16:30
JavaScript random integer range expression, function randomInt
//main formula Math.floor(Math.random() * (max - min + 1)) + min;
function randomInt(min,max) {
return Math.floor(Math.random() * (max - min + min)) + min;
}
@psycalc
psycalc / gist:8c1d04af446af3abcbd8d363dc57e655
Created June 20, 2016 14:28
The map method is a convenient way to iterate through arrays.
//The map method is a convenient way to iterate through arrays. Here's an example usage:
var timesFour = oldArray.map(function(val){
return val * 4;
});
//The map method will iterate through every element of the array, creating a new array with values that have been modified by the callback function, and return it. Note that it does not modify the original array.
//In our example the callback only uses the value of the array element (the val argument) but your callback can also include arguments for the index and array being acted on.
//Use the map function to add 3 to every value in the variable oldArray, and save the results into variable newArray. oldArray should not change.
@psycalc
psycalc / restAPIExample.ps
Created June 22, 2016 12:16
How to make simple rest api query from powershell, curl windows alternative
$apiKey = "" #access key сopy pase from rest api provider
$uri = "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies" #uri of rest api provider
Invoke-RestMethod -Method Get -Uri $uri -Header @{ "X-Mashape-Key" = $apiKey }