Skip to content

Instantly share code, notes, and snippets.

View allaniftrue's full-sized avatar

Tux allaniftrue

  • 12:53 (UTC +08:00)
View GitHub Profile
@allaniftrue
allaniftrue / scrollToTop.js
Created September 8, 2017 14:01
Vanilla Javascript scrolling
scrollToTop = (scrollDuration) => {
if(navigator.userAgent.match(/Trident\/7\./)) { // if IE
window.scrollTo(0, 0);
} else {
const scrollHeight = window.scrollY,
scrollStep = Math.PI / (scrollDuration / 15),
cosParameter = scrollHeight / 2;
var scrollCount = 0,
scrollMargin,
scrollInterval = setInterval(function() {
@allaniftrue
allaniftrue / Product.php
Last active September 7, 2017 06:18
Sorting JSON in php
<?php
class Product {
/**
* Compare obj by price
* Compare obj by name if prices are equal
* @param stdClass $a product a
* @param stdClass $b product b
* @return int -1, 0, 1
@allaniftrue
allaniftrue / toLowercase.sh
Created September 5, 2017 02:16
Gist of linux commands
# Linux command to lowercase files inside the current directory (pwd).
for f in `find`; do mv -v "$f" "`echo $f | tr '[A-Z]' '[a-z]'`"; done
@allaniftrue
allaniftrue / vue.html
Created August 10, 2017 03:28
A Vue.js sample to add, update, delete items in an array.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
<input type="text" v-model="item.value">
<button type="button" @click="addItem" :disabled="!item.value">Add</button>
@allaniftrue
allaniftrue / countdown.js
Created June 29, 2017 07:45
A sample of using javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Count Down</title>
</head>
<body>
<h1 id="countDownContainer"></h1>
self.on('*.submitOnepass', function () {
var countryCode = (self.get('displayCountryCode')) ? self.get('selectedCountryCode') + '-' : '';
this.set('ssoLoginUserid', countryCode + self.get('loginid'));
this.set('countryCode', countryCode);
this.set('username', countryCode + self.get('loginid'));
this.set('tempCcode', ((self.get('displayCountryCode')) ? '+' : '') + countryCode);
this.set('loginUserid', self.get('loginid'));
this.set('loading', true);
@allaniftrue
allaniftrue / index.html
Created April 19, 2017 09:57
A vuejs filtering of collection sample
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="app">
<div class="row">
<input type="text" name="" v-model="keyword">
@allaniftrue
allaniftrue / track.js
Last active March 8, 2017 03:45
Trigger track event when scrolling reaches the section
var o1 = o1 || {};
o1.panel0 = document.getElementsByClassName('sd-component-imagetextbanner-singtel')[0],
o1.panel1 = document.getElementsByClassName('sd-component-imagetextbanner-singtel')[1],
o1.panel2 = document.getElementsByClassName('sd-component-imagetextbanner-singtel')[2],
o1.panel3 = document.getElementsByClassName('sd-component-imagetextbanner-singtel')[3],
o1.panel4 = document.getElementsByClassName('sd-component-imagetextbanner-singtel')[4]
o1.panel5 = document.getElementsByClassName('sd-component-pagesection-singtel')[0],
o1.panel6 = document.getElementsByClassName('sd-component-pagesection-singtel')[1],
o1.panel0Trigger = false,
o1.panel1Trigger = false,
@allaniftrue
allaniftrue / bootstrap.js
Created January 15, 2017 13:37
From vue-resource to axios configuration
window.axios = require('../../../node_modules/axios/dist/axios');
Vue.prototype.$http = axios;
axios.interceptors.request.use(function(config){
config.headers['X-CSRF-TOKEN'] = Laravel.csrfToken
return config;
})
@allaniftrue
allaniftrue / PinEncryption.php
Created January 5, 2017 03:41
Encrypting a password with a self-signed certificate
<?php
/**
*
* @param $password A user defined password
* @return string
*
*/
public function encryptPasswordToRsaBase64(string $password): string
{
$publicKey = fopen('/path/to/public/key.pem', 'r');