Skip to content

Instantly share code, notes, and snippets.

View edysegura's full-sized avatar
👽
Always learning!

Edy Segura edysegura

👽
Always learning!
View GitHub Profile
@edysegura
edysegura / .brackets.json
Last active August 29, 2015 14:23
[JSON] Brackets configuration
{
"sass.options": {
"outputDir": "../styles"
},
"linting.enabled": true,
"language": {
"javascript": {
"linting.prefer": "JSHint",
"linting.usePreferredOnly": true
}
@edysegura
edysegura / javascript-ninja-tricks.js
Last active September 16, 2015 23:01
[JS] JavaScript Ninja Tricks
//convert a string to number
+'2' //2
+'2a' //NaN
//convert anything to boolean
!!'it will be converted to true' //true
!!'' //false
@edysegura
edysegura / nodejs-process.js
Last active August 29, 2015 14:22
[nodejs] How to pass command line arguments to Node.js? https://nodejs.org/docs/latest/api/process.html#process_process_argv
// print process.argv
process.argv.forEach(function(val, index, array) {
console.log(index + ': ' + val);
});
//$ node process.js one two=three four
//0: node
//1: /Users/mjr/work/node/process-2.js
//2: one
//3: two=three
@edysegura
edysegura / screenshot.js
Last active August 29, 2015 14:21
[JS] Take a snapshot with PhantomJS
var page = require('webpage').create();
page.open('http://edysegura.com', function () {
var title = page.evaluate(function () {
return document.title;
});
page.clipRect = { top: 0, left: 0, width: 600, height: 700 };
page.render(title + ".png");
phantom.exit();
});
@edysegura
edysegura / MathService.js
Last active January 7, 2016 16:52
[JS] Example of Automated Test with Jasmine
var MathService = {
add: function() {
var amount = arguments.length;
var total = 0;
if(amount > 0) {
for(var i=0; i<amount; i++) {
var currentNumber = parseInt(arguments[i], 10);
if(isNaN(currentNumber)) return null;
@edysegura
edysegura / random.js
Last active August 29, 2015 14:20
[JS] Unique ID with JS - source http://jsbin.com/telokagigo/3/edit?js,console
function random(seed) {
if (!seed)
seed = new Date().getTime();
seed = (seed*9301+49297) % 233280;
return seed/(233280.0) * 100;
}
function seed() {
var seedNumber = (Math.random() * Math.pow(10, 17) + Math.random() * Math.pow(10, 17) + Math.random() * Math.pow(10, 17) + Math.random() * Math.pow(10, 17));
return seedNumber;
@edysegura
edysegura / no-user-selection.css
Created March 19, 2015 14:09
[CSS] How to disable user selection
.no-selection {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@edysegura
edysegura / html-to-quotes
Last active August 29, 2015 14:17
[REGEX] Put HTML code into quotes
find
^(\s+)?<
replace
$1'<
find
>$
replace
@edysegura
edysegura / angularjs-interceptor.js
Last active May 12, 2023 15:37 — forked from gnomeontherun/angularjs-interceptor.js
[angularjs] How to create an AngularJS HTTP Interceptor
// Intercepting HTTP calls with AngularJS.
angular.module('MyApp', [])
.config(function ($provide, $httpProvider) {
// Intercept http calls.
$provide.factory('MyHttpInterceptor', function ($q) {
return {
// On request success
request: function (config) {
// console.log(config); // Contains the data about the request before it is sent.
@edysegura
edysegura / browser-detection.js
Last active September 16, 2015 23:03
[JS] Browser Detection
var result = navigator.userAgent.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i);
//output: ["Chrome/41.0.2272.76", "Chrome", "41.0.2272.76", ".76"]