Skip to content

Instantly share code, notes, and snippets.

View cafeasp's full-sized avatar

Victor Pacheco cafeasp

View GitHub Profile
@cafeasp
cafeasp / SqlBackup.cs
Created February 28, 2017 20:50
C# SQL Backup
public class BackupService
{
private readonly string _connectionString;
private readonly string _backupFolderFullPath;
private readonly string[] _systemDatabaseNames = { "master", "tempdb", "model", "msdb" };
public BackupService(string connectionString, string backupFolderFullPath)
{
_connectionString = connectionString;
_backupFolderFullPath = backupFolderFullPath;
@cafeasp
cafeasp / IsWebHookAuthentic.cs
Created March 10, 2017 12:53
Is web hook authentic
public bool IsAuthenticWebhook(NameValueCollection requestHeaders, string requestBody, string shopifySecretKey)
{
string hmacHeader = requestHeaders.Get("X-Shopify-Hmac-SHA256");
if (string.IsNullOrEmpty(hmacHeader))
{
return false;
}
HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(shopifySecretKey));
@cafeasp
cafeasp / CreateFolder.cs
Created March 20, 2017 17:23
Google Drive API C# - Create a folder
private static void CreateFolder(string folderName,DriveService service)
{
var fileMetadata = new Google.Apis.Drive.v3.Data.File()
{
Name = folderName,
MimeType = "application/vnd.google-apps.folder"
};
var request = service.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();
@cafeasp
cafeasp / appSettings.config
Created August 10, 2018 18:46
Any mvc web app can use this file to set your private settings on a different path in your computer.
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="AppId" value="your_app_id" />
<add key="AppSecret" value="your_app_secret" />
<add key="AppScope" value="read_orders,write_orders" />
</appSettings>
@cafeasp
cafeasp / RestletExample.js
Created May 19, 2019 16:21
NetSuite Restlet Template
/**
* @NApiVersion 2.x
* @NScriptType Restlet
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record'],
/**
* @param {search} search
* @param {record} record
*/
@cafeasp
cafeasp / index.js
Created May 24, 2019 02:38
Node js - Quickstart
const fs = require('fs');
const readline = require('readline');
const { google } = require('googleapis');
//Drive API, v3
//https://www.googleapis.com/auth/drive See, edit, create, and delete all of your Google Drive files
//https://www.googleapis.com/auth/drive.file View and manage Google Drive files and folders that you have opened or created with this app
//https://www.googleapis.com/auth/drive.metadata.readonly View metadata for files in your Google Drive
//https://www.googleapis.com/auth/drive.photos.readonly View the photos, videos and albums in your Google Photos
//https://www.googleapis.com/auth/drive.readonly See and download all your Google Drive files
// If modifying these scopes, delete token.json.
@cafeasp
cafeasp / CreateCustomerDeposit.js
Created July 12, 2019 00:10
NetSuite - Create Customer Deposit
function CreateCustomerDeposit(salesOrderId, paymentMethod) {
try {
if (paymentMethod != 'free') {
var order = record.load({
id: salesOrderId,
type: record.Type.SALES_ORDER,
isDynamic: true
});
@cafeasp
cafeasp / CheckDuplicateValue.js
Last active July 15, 2019 16:23
NetSuite SuiteScript 2.0
function IsNewOrder(orderId) {
var s = search.create({
type: search.Type.SALES_ORDER,
filters: [
['mainline', 'is', 'T'], 'and',
['trandate', 'onorafter', '04/01/2019'], 'and',
['otherrefnum', 'equalto', orderId]
],
columns: ['otherrefnum']
}).run().getRange({
@cafeasp
cafeasp / restlet_item_fulfillment.js
Created July 15, 2019 17:08
NetSuite - Suite Script Create Item Fulfillment
/**
* @NApiVersion 2.x
* @NScriptType Restlet
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record', 'N/util', './momentjs.js', './cafeaspMagento.js'],
/**
* @param {search} search
* @param {record} record
* @param {util} util
@cafeasp
cafeasp / LoadSaveSearch.js
Created July 15, 2019 19:14
NetSuite Load Save Search
function RunSaveSearch() {
var mySearch = search.load({
id: '111111'
});
var array = [];
mySearch.run().each(function (result) {
log.debug('result', result);
var netamount = result.getValue({
name: 'netamount'