Skip to content

Instantly share code, notes, and snippets.

View prasann's full-sized avatar
💬
Living by the code

Prasanna V Nagarajan prasann

💬
Living by the code
View GitHub Profile
@prasann
prasann / page_load.js
Created March 4, 2015 12:50
Page load time in JS
$(document).ready(function () {
if (typeof(console) !== 'undefined' && console.log) {
var now = new Date().getTime();
var page_load_time = now - performance.timing.navigationStart;
console.log("Page loading time: " + page_load_time + ' ms');
}
});
@prasann
prasann / precompile_hook.rake
Created July 29, 2015 14:53
A precompile hook to precompile CKEditor assets.
require 'fileutils'
desc "Create nondigest versions of all ckeditor digest assets"
task "assets:precompile" => :environment do
fingerprint = /\-([0-9a-f]{32})\./
for file in Dir["public/assets/ckeditor/**/*"]
# Skip file unless it has a fingerprint
next unless file =~ fingerprint
# Get filename of this file without the digest
<?xml version="1.0" encoding="UTF-8"?>
<Projects>
<Project name="main :: build" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="0.1008 :: 2" lastBuildTime="2011-08-29T15:22:58" webUrl="http://172.18.20.31:8153/go/pipelines/main/1008/build/2"/>
<Project name="main :: build :: build" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="0.1008 :: 2" lastBuildTime="2011-08-29T15:22:58" webUrl="http://172.18.20.31:8153/go/tab/build/detail/main/1008/build/2/build"/>
<Project name="main :: build :: metrics" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="0.1008 :: 2" lastBuildTime="2011-08-29T15:20:46" webUrl="http://172.18.20.31:8153/go/tab/build/detail/main/1008/build/2/metrics"/>
<Project name="main :: deploy-to-dev" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="0.1008 :: 2" lastBuildTime="2011-08-29T15:25:25" webUrl="http://172.18.20.31:8153/go/pipelines/main/1008/deploy-to-dev/2"/>
<Project name="main :: deploy-to-dev :: deploy-to-dev" activity="Sle
require 'uri'
require 'net/https'
require 'json'
GITLAB_URL = 'https://gitlab-your-url.com'
USERS_API = '/api/v3/users'
PRIVATE_TOKEN='XXXXXXXXX' #Private token from Git-lab profile.
DEFAULT_PASSWORD = 'some_default_password'
import org.springframework.security.authentication.CredentialsExpiredException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
public class SessionExpiryFilter implements Filter {
private final int maxSessionLifeInMinutes;
@prasann
prasann / DynamicSessionIdentifierStrategy.java
Last active June 17, 2017 18:57
Dynamically set session expiry based on the user type
public class DynamicSessionIdentifierStrategy implements HttpSessionStrategy {
private static CookieHttpSessionStrategy cookieHttpSessionStrategy =
new CookieHttpSessionStrategy();
/* Code redacted */
@Override
public void onNewSession(Session session, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
if (!principalManager.isLoggedIn()) {
@prasann
prasann / mock-jest-locale.js
Created September 17, 2017 14:56
Sample Jest test to mock localeString
import * as helpers from '../src/helpers';
describe('formatDate', () => {
it('should invoke localString implementation to format date ', () => {
const localStringMock = jest.fn();
const mockDate = { toLocaleString: localStringMock };
helpers.formatDate(mockDate);
expect(localStringMock).toHaveBeenCalledWith('de-DE', {
year: 'numeric',
month: '2-digit',
day: '2-digit',

Keybase proof

I hereby claim:

  • I am prasann on github.
  • I am prasann (https://keybase.io/prasann) on keybase.
  • I have a public key ASAQVtwyhQ1XUFYNoIpqxm2JG32G_B_yMdt5oVARSQCYpAo

To claim this, I am signing this object:

An h1 header

Paragraphs are separated by a blank line.

2nd paragraph. Italic, bold, and monospace. Itemized lists look like:

  • this one
  • that one
alert('Injected!');