Skip to content

Instantly share code, notes, and snippets.

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

Arup Sen ArupSen

🏠
Working from home
View GitHub Profile
// challenge description
// sample input -
// sample output -
function coolFunction (input) {
var dataStruct = []; // or {}
var output = ""; // or 0
dataStruct = input.split(',');
output = dataStruct.join(' ');
return output;
@ArupSen
ArupSen / device_sniffer.php
Created December 16, 2013 17:05
PHP device sniffer. Do stuff on the server side.
<?php
//Detect special conditions devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
//do something with this information
@ArupSen
ArupSen / org.chameleon.Boot.plist
Created October 9, 2013 22:15
This is for Mountain Lion 10.8.5 running on a Dell Optiplex 755 quad core with an EVGA 8400 GS card. EFI string used to get full resolution. Was about to buy a new card but this worked. Phew.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EthernetBuiltIn</key>
<string>Yes</string>
<key>GenerateCStates</key>
<string>Yes</string>
<key>GeneratePStates</key>
<string>Yes</string>
@ArupSen
ArupSen / randomstring.js
Last active December 24, 2015 01:09
A simple random string generator of any length. Only lower case characters a-z.
function randomString(stringLen) {
var lowerChars = 'abcdefghijklmnopqrstuvwxyz';
var randomString = '';
for (var i=0; i < stringLen; i++) {
var rNum = Math.floor(Math.random() * 25);
randomString += lowerChars.charAt(rNum);
}
return randomString;
}
@ArupSen
ArupSen / botanique_homepage.html
Created May 24, 2013 11:03
Botanique homepage has slideshow and a row of three images.
<div class="pics"><img src="//cdn.shopify.com/s/files/1/0223/3783/files/botanique-home-page-slide-2.jpg?300" />
<img src="//cdn.shopify.com/s/files/1/0223/3783/files/slide2.jpg?302" />
</div>
<ul>
<li><img src="//cdn.shopify.com/s/files/1/0223/3783/files/home-pic1.jpg?231" />
<h2>A GROWING MOVEMENT</h2>
<p>Lovely terrariums that create their own biospheres so that you need not water your houseplants ever again.</p>
</li>
<li><img src="//cdn.shopify.com/s/files/1/0223/3783/files/home-pic1.jpg?231" />
<h2>THE STATEMENT PIECE</h2>
@ArupSen
ArupSen / shopify_preload_images.html
Created May 21, 2013 23:24
The short js script adds each alternate image that will be swapped on mouseover to the document.images array. I'm using the liquid syntax to increment the img(n) variable for each product. Without the preloader it takes about a second to load the image on mouseover. This way the whole page takes a touch longer to load but the effect is immediate…
{% for product in collection.products %}
<script type="text/javascript">
// preload alternate image
if (document.images) {
img{{ forloop.index }} = new Image();
img{{ forloop.index }}.src = "{{ product.images.first | product_img_url: 'large' }}";
img{{ forloop.index }}.src = img{{ forloop.index }}.src.replace('_large.','_alt.');
}
</script>
<div class = "product">
@ArupSen
ArupSen / product_tab_template.html
Created May 21, 2013 23:08
In order for the jquery ui tabs to work they need to follow this html structure. You only need to edit content between the <p></p> tags. The rest can remain intact.
<div id="tabs">
<ul>
<li><a href="#tabs-1">Description:</a></li>
<li><a href="#tabs-2">Care:</a></li>
</ul>
<div id="tabs-1">
<p>Usually stemless, the leaves can spread up to 25cm across. Brachycaulos Abdita has an open rosette with beautiful grassy green leaves that curl out from its thick base.In bloom, the leaves turn an absolutely stunning shade of bright pink.They are good rooters too,
and send out loads of roots which attaches to its mounting very quickly.</p>
<p>*Please bear in mind, each plant is a unique individual with its own quirky character and looks.*</p>
</div>
@ArupSen
ArupSen / iphone_sniff.html
Last active December 15, 2015 11:38
Is it an iOS device? The iOS sniffer could redirect to a non-flash page or as in the example swap the div containing the flash content with a static image .
<script type="text/javascript" charset="utf-8">
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
// examples
// if you need to add more complex js then of course put this script just above the </body> tag
document.location = "http://sassalina.com/iphone/";
document.getElementById("movie").innerHTML="<img src='http://talismangallery.co.uk/wp-content/uploads/2010/04/talisman-gallery-intro.jpg'>";
}
</script>
@ArupSen
ArupSen / python_boilerplate.py
Created December 17, 2012 15:46
Basic boilerplate for a python script file
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""[application description here]"""
def main():
pass
if __name__ == '__main__': main()
@ArupSen
ArupSen / init_twitter.js
Created November 19, 2012 12:17
Grab Twitter Feed
/* Grab Twitter Feed
Look at the url of the api that will change to /1.1 from march 2013
callback=twitterCallback2 still works
http://twitter.com/statuses/<username>.json? no longer works
*/
function init_twitter() {
$.getJSON('https://api.twitter.com/1/statuses/user_timeline.json?screen_name='+ twitterID +'&count=1&callback=?&include_rts=true', function(data){
var tweet = data[0];