Skip to content

Instantly share code, notes, and snippets.

View frhan's full-sized avatar

Farhan Faruque frhan

View GitHub Profile
<html>
<head>
</head>
<body>
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
package main
import "fmt"
func BinarySearch(arr [] int, x int) bool{
var lowerBound int = 0
var higherBound int = len(arr) - 1
for lowerBound <= higherBound {
var midPoint = lowerBound + (higherBound - lowerBound) /2
public static void addProductIdHeader(EditionService service, final String artId, HttpServletResponse response) {
//1) has access to all editions always
StringBuilder xpids = new StringBuilder("1");
boolean isD2 = service.isArticleAvailableToEdition(artId, EditionService.D2_EDITION, null);
logger.debug("Article id:"+artId+" D2 edition:"+isD2);
boolean isMag = service.isArticleAvailableToEdition(artId, EditionService.MAGAZINE_EDITION, null);
logger.debug("Article id:"+artId+" Magazine edition:"+isMag);
@frhan
frhan / paywall.java
Last active September 22, 2016 05:27
public static void addProductIdHeader(HttpServletResponse response, String pidDate,
String articleHomeSection,
boolean isArticleAvailableToCurrentEd){
DateTime now;
if(pidDate == null) {
now = new DateTime(DateTimeZone.forID("CET"));
} else {
String[] fakeDate = pidDate.split("/");
now = new DateTime(Integer.valueOf(fakeDate[2]),
Integer.valueOf(fakeDate[1]),
You can do page up/down and home/end on a Macbook keyboard by using the fn and the arrow keys:
fn+↑ is PageUp
fn+↓ is PageDown
fn+← is Home
fn+→ is End
Cmd + spacebar Top Search bar
@frhan
frhan / ubuntu_custom_lanucher
Created March 16, 2015 04:39
Create a custom launcher for Unity
1. Create a .desktop file
Create a desktop launcher (or shortcut) for your application.
touch rubymine.desktop
For RubyMine, mine looks like this:
[Desktop Entry]
Version=1.0
@frhan
frhan / java_home_setup
Created March 12, 2015 08:07
Java Home Setup
# copy jdk from downloads to /usr/local/java
sudo cp -r jdk-7u45-linux-x64.tar.gz /usr/local/java
# extract the folder
sudo tar xvzf jdk-7u45-linux-x64.tar.gz
#set home variable
sudo nano ~/.bashrc
JAVA_HOME=/usr/local/java/jdk1.7.0_45
JRE_HOME=$JAVA_HOME/jre
$("#profile_picture").change(function () {
readURL(this);
});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#image_preview')
.attr('src', e.target.result)
@frhan
frhan / ealyH.markdown
Last active August 29, 2015 14:08
A Pen by Farhan Faruque.
@frhan
frhan / edit and add var-www
Last active September 28, 2022 00:07
the simplest way to edit and add files to “/var/www”
if you make /var/www writeable by its group and add the user to the group, that user will not have to use sudo. Try this:
sudo adduser <username> www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www
The user should then be able to edit /var/www/ files without hassle.
The first line adds the user to the www-data group, the second line clears up any files with messed up ownership, and the third makes it so that all users who are members of the www-data group can read and write all files in /var/www.
If you are logged in as <username> you need to log out and log back in for the group membership to take effect.