Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View AugustoPedraza's full-sized avatar

Augusto AugustoPedraza

  • San Miguel de Tucumán
View GitHub Profile
@AugustoPedraza
AugustoPedraza / ActiveDirectory.cs
Created March 18, 2014 17:47
Listing users and groups from ActiveDirectory
using System;
using System.Collections.Generic;
using System.DirectoryServices.AccountManagement;
using System.Linq;
namespace AugustoPedraza.Utils
{
public class ActiveDirectory
{
public static string Domain { get; set; }
@AugustoPedraza
AugustoPedraza / ranking-sort.js
Last active August 29, 2015 14:01
Really simpler chrome console "ñoño" filter sorter for http://torrentbutler.eu/
var internalId = setInterval(function() {
$("html, body").animate({ scrollTop: $(document).height()-$(window).height() });
setTimeout(function() {
$('a.movie').each(function(i, el) {
var $el = $(el);
var styleValue = $($el.find('span.rating > span')[0]).attr('style');
var ranking = parseFloat((styleValue || '-1').substring(7).replace("%;", ''));
if (isNaN(ranking)|| ranking < 80) {
$el.remove();
# Given the word list, count how many words are in the dictionary.
# Note: This isn't the most efficient way to do thise. If I was going for
# speed, I would have made each dicitonary word the key of a hash, and
# had O(n) lookup times.
def process_words(words, dictionary)
puts "Starting thread #{Thread.current.object_id}\n"
found = 0
words.each do |word|
if dictionary.include? word
@AugustoPedraza
AugustoPedraza / specs_outline.rb
Created October 31, 2015 15:03
WEDIDIT- Rails Engineer Interview : Mini-coding exercise
## Given the following User Story:
## As a registered User,
## I want to send a technical request to the sys admin,
## So that they are aware I have a problem.
## Acceptance criteria
## * Email sent to ENV['ADMIN_EMAIL']
## Provide a "spec outline" which clearly shows what you will be testing, illustrated by file locations and
## statement hierarchy without actually writing any [implementation] code, for example:
@AugustoPedraza
AugustoPedraza / the_method_invocation_pattern.js
Created March 4, 2013 13:44
When a function is stored as a property of object, we call it a "method". When a method is invoked, "this" is bound to that object. If an invocation expression contains a refinement (that is, a "." expression or [subscript]expression), it is invoked as a method: //Show code... A method can use "this" to access to object so that it can retrieve v…
//Create myObject. It has a value and an increment method.
//The increment method takes a optional parameter.
//If the argument is not a number, then 1 is used as the default.
var myObject = {
value: 0,
increment: function(inc){
this.value +=
typeof inc === 'number' ? inc : 1;
}
@AugustoPedraza
AugustoPedraza / the_function_invocation_pattern.js
Created March 4, 2013 14:09
var sum = add(3, 4); //sum is 7 When a function is invoked with this pattern, "this" is bound to the global object. If the methods defines a variable and assigns it the value of "this", the inner function will have access to "this" through that variable. By convention, the name of that variable is "that". This text and example was taken from the…
//Augment myObject with a double method.
add = function(a, b){ return a + b; };
var myObject = { value: 0 };
myObject.double = function( ){
var that = this; //Workaround
var helper = function( ){ that.value = add(that.value, that.value); };
@AugustoPedraza
AugustoPedraza / the_constructor_invocation_pattern.js
Created March 4, 2013 14:36
If a function is invoked with the "new" prefix, then a new object will be created with a hidden link to the value of the function's PROTOTYPE member, and "this" will be bound to that new object. The "new" prefix also changes the behavior of the "return" statement... //Show code... Functions that are intended to be used with the "new" prefix are …
//Create a constructor function called Quo.
//It makes an object with a status property.
var Quo = function(string){ this.status = string; };
//Gives all instances of Quo a public method called getStatus.
Quo.prototype.getStatus = function( ){ return this.status; };
//Make an instance of Quo.
@AugustoPedraza
AugustoPedraza / the_apply_invocation_pattern.js
Created March 4, 2013 15:01
Because JavaScript is a functional object-oriented language, functions can have methods. The "apply" methods lets us construct an array of arguments to use to invoke a function. It also lets us choose the value of "this". The "apply" methods takes two parameters. The first is the value that should be bound to "this". The second is an array of pa…
add = function(a, b){ return a + b; };
//Make an array of 2 numbers and add them.
var array = [3, 4];
var sum = add.apply(null, array); //sum is 7
console.log(sum);
/*----------------------------------------*/
@AugustoPedraza
AugustoPedraza / exception_sample.js
Created March 4, 2013 15:26
Exceptions example. This example was taken from the book "Javascript: The Good Parts".
var add = function(a, b){
var invalidTypes = (typeof a !== 'number' || typeof b !== 'number');
if(invalidTypes){
throw {
name: "TypeError",
message: "add needs numbers"
};
}
@AugustoPedraza
AugustoPedraza / extract_integer_from_number.js
Created March 4, 2013 15:53
Simple augmenting function to "Function.prototype" to extract just the integer part of a number and removes spaces from the ends of a string. This example was taken from the book "Javascript: The Good Parts".
//Define method to add a method available to all functions.
Function.prototype.method = function(name, func){
this.prototype[name] = func;
return this;
};
Number.method('integer', function( ){
return Math[this < 0 ? 'ceil' : 'floor'](this);
})