Skip to content

Instantly share code, notes, and snippets.

View pushandplay's full-sized avatar
:octocat:
💻💰

Master of life pushandplay

:octocat:
💻💰
View GitHub Profile
@pushandplay
pushandplay / 1.coffee
Created April 21, 2015 10:54
adapter-pattern
# a fragment of 3-rd party grid component
class AwesomeGrid
constructor: (@datasource)->
@sort_order = 'ASC'
@sorter = new NullSorter # in this place we use NullObject pattern (another useful pattern)
setCustomSorter: (@customSorter) ->
@sorter = customSorter
sort: () ->
@datasource = @sorter.sort @datasource, @sort_order
# don't forget to change sort order
// 5 columns layout for bootstrap
.col-xs-2_4,
.col-sm-2_4,
.col-md-2_4,
.col-lg-2_4
position: relative
min-height: 1px
padding-right: 10px
padding-left: 10px
@pushandplay
pushandplay / randomcolor
Created March 5, 2015 22:16
Random color with JavaScript
"#" + ((1<<24)*Math.random()|0).toString(16)
@pushandplay
pushandplay / extractiOSVersion
Created November 14, 2014 23:52
Extract iOS Version
(navigator.userAgent).match(/OS\s+([\d\_]+)/i)[0].replace(/_/g, '.').replace('OS ', '')
<?php
$applesharedsecret = "XXXXXXXXXXX";
$receiptbytes = $_POST['receiptbytes'];
//$appleurl = "https://buy.itunes.apple.com/verifyReceipt"; // for production
$appleurl = "https://sandbox.itunes.apple.com/verifyReceipt"; // for testing
$request = json_encode(array("receipt-data" => $receiptbytes,"password"=>$applesharedsecret));
$ch = curl_init($appleurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
@pushandplay
pushandplay / Makefile Tricks
Created September 18, 2014 20:50
Makefile Tricks: Arithmetic – Addition, Subtraction, Multiplication, Division, Modulo, Comparison
NUMBER1 := 10
NUMBER2 := 5
#Addition
ADD := $(shell echo ${NUMBER1}+${NUMBER2} | bc)
#Subtraction
SUBTRACT := $(shell echo ${NUMBER1}-${NUMBER2} | bc)
#Multiplication
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
</template>
<script>
<link rel="import" href="../paper-button/paper-button.html">
<polymer-element name="my-element">
<template>
<style>
#paper_button {
left: 310px;
top: 110px;
position: relative;
@pushandplay
pushandplay / detectbrowser.coffee
Last active November 8, 2019 09:50
Detect Browser version (Yandex.Browser support)
navigator.checkBrowser = ->
ua = navigator.userAgent
M = ua.match(/(opera|yabrowser|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)
if /trident/i.test(M[1])
tem = /\brv[ :]+(\d+)/g.exec(ua) or []
return name: 'ie', version: (tem[1] or '')
if M[1] is 'Chrome'
if (tem = ua.match(/\bOPR\/(\d+)/))?
return name: 'opera', version: tem[1]
if (tem = ua.match(/\bYaBrowser\/(\d+)/))?
// Pre-requisites:
// 1. Device core plugin
// 2. Splashscreen core plugin (3.1.0)
// 3. config.xml: <preference name="AutoHideSplashScreen" value="false" />
// 4. config.xml: <preference name="DisallowOverscroll" value="true" />
function onDeviceReady() {
if (parseFloat(window.device.version) >= 7.0) {
document.body.style.marginTop = "20px";
// OR do whatever layout you need here, to expand a navigation bar etc