Skip to content

Instantly share code, notes, and snippets.

View sawant's full-sized avatar
🏠
Working from home

Sawant Shah sawant

🏠
Working from home
View GitHub Profile
@sawant
sawant / Pakistan Internet Censorship.md
Last active August 29, 2015 13:55
A number of websites and online services, which were previously operational, have stopped working in Pakistan since 1st Feb.

A number of websites and online services, which were previously operational, have stopped working in Pakistan since 1st Feb (verified on PTCL and Cybernet, in Karachi). The sites appear broken and their services, if any, are not working as intended. This could be a temporary glitch, or it could be a side-effect of the Pakistani government/PTA banning websites and IP addresses.

Following are the sites/services I have come across that are not working entirely or partially from Karachi, Pakistan (if you come across any others, tweet them to @sawant):

@sawant
sawant / Pakistan Internet Censorship - Feb 2014.md
Last active August 29, 2015 13:55
Previously operational websites and online services, which seem to have stopped working in Pakistan since 1st Feb 2014.

New Wave of Inaccessible/Blocked websites and services

A number of websites and online services, which were previously operational, have stopped working in Pakistan since 1st Feb (verified on PTCL, Cybernet and Multinet, in Karachi). The sites appear broken and their services, if any, are not working as intended. This could be a temporary glitch, or it could be a side-effect of the Pakistani government/PTA banning websites and IP addresses.

Following are the sites/services I have come across that are not working entirely or partially (report any other sites/services in the comments or tweet them to @sawant):

List of Inaccessible / Blocked Websites

@sawant
sawant / ascii-triangle.js
Created August 27, 2014 11:55
JavaScript ASCII Right Triangle
/*
http://eloquentjavascript.net/02_program_structure.html
Write a loop that makes seven calls to console.log to output the following triangle:
#
##
###
####
#####
@sawant
sawant / power.js
Created August 27, 2014 16:00
JavaScript Power Recursive
var power = function(base, exp) {
if (exp == 1)
return base;
else
return base * power(base, exp-1);
}
console.log(power(2, 7));
@sawant
sawant / iseven.js
Created August 27, 2014 16:40
3.2 Recursion
/*
We’ve seen that % (the remainder operator) can be used to test whether a number is even or odd by using % 2 to check whether it’s divisible by two. Here’s another way to define whether a positive whole number is even or odd:
Zero is even.
One is odd.
For any other number N, its evenness is the same as N - 2.
Define a recursive function isEven corresponding to this description. The function should accept a number parameter and return a Boolean.
/*
http://eloquentjavascript.net/04_data.html
Write a range function that takes two arguments, start and end, and returns an array containing all the numbers from start up to (and including) end.
Next, write a sum function that takes an array of numbers and returns the sum of these numbers. Run the previous program and see whether it does indeed return 55.
As a bonus assignment, modify your range function to take an optional third argument that indicates the “step” value used to build up the array. If no step is given, the array elements go up by increments of one, corresponding to the old behavior. The function call range(1, 10, 2) should return [1, 3, 5, 7, 9]. Make sure it also works with negative step values so that range(5, 2, -1) produces [5, 4, 3, 2].
*/
@sawant
sawant / 4-4-deepcomparison.js
Created September 2, 2014 14:01
The == operator compares objects by identity. But sometimes, you would prefer to compare the values of their actual properties. Write a function, deepEqual, that takes two values and returns true only if they are the same value or are objects with the same properties whose values are also equal when compared with a recursive call to deepEqual. T…
/*
http://eloquentjavascript.net/04_data.html
The == operator compares objects by identity. But sometimes, you would prefer to compare the values of their actual properties.
Write a function, deepEqual, that takes two values and returns true only if they are the same value or are objects with the same properties whose values are also equal when compared with a recursive call to deepEqual.
To find out whether to compare two things by identity (use the === operator for that) or by looking at their properties, you can use the typeof operator. If it produces "object" for both values, you should do a deep comparison. But you have to take one silly exception into account: by a historical accident, typeof null also produces "object".
*/
<?php
function omit_twitter_script($provider, $url, $args) {
//get the hostname of the oEmbed endpoint provider being called
$host = parse_url($provider, PHP_URL_HOST);
//check to see that hostname is twitter.com
if (strpos($host, 'twitter.com') !== false) {
//adding ?omit_script=true to oEmbed endpoint call stops the returned HTML from containing widgets.js
$provider = add_query_arg('omit_script', 'true', $provider);
}
//return the $provider URL so the oEmbed can be fetched
// Bonfire: Confirm the Ending
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending?solution=function%20end(str%2C%20target)%20%7B%0A%20%20%2F%2F%20%22Never%20give%20up%20and%20good%20luck%20will%20find%20you.%22%0A%20%20%2F%2F%20--%20Falcor%0A%20%20return%20str.substr(-target.length)%20%3D%3D%3D%20target%3B%0A%7D%0A%0Aend(%22Bastian%22%2C%20%22n%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
return str.substr(-target.length) === target;
}
// Bonfire: Repeat a string repeat a string
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string?solution=function%20repeat(str%2C%20num)%20%7B%0A%20%20%2F%2F%20repeat%20after%20me%0A%20%20return%20num%20%3E%200%20%3F%20str.repeat(num)%20%3A%20%22%22%3B%0A%7D%0A%0Arepeat(%22abc%22%2C%203)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function repeat(str, num) {
// repeat after me
return num > 0 ? str.repeat(num) : "";
}