Skip to content

Instantly share code, notes, and snippets.

View hnq90's full-sized avatar
🥑

Huy Nguyen Quang hnq90

🥑
View GitHub Profile
@hnq90
hnq90 / grape_routes.rb
Last active August 29, 2015 13:57
List all routes of grape app and export to text file
desc 'Generate API Desc'
task :api_desc => :environment do
=begin
___ ___ ___ ___ ___ ___ ________ ________
|\ \|\ \|\ \|\ \ |\ \ / /|\ ___ \|\ __ \
\ \ \\\ \ \ \\\ \ \ \ \/ / | \ \\ \ \ \ \|\ \
\ \ __ \ \ \\\ \ \ \ / / \ \ \\ \ \ \ \\\ \
\ \ \ \ \ \ \\\ \ \/ / / \ \ \\ \ \ \ \\\ \
\ \__\ \__\ \_______\__/ / / \ \__\\ \__\ \_____ \
\|__|\|__|\|_______|\___/ / \|__| \|__|\|___| \__\
@hnq90
hnq90 / Calculate size
Last active August 29, 2015 14:01
Calculate size of a file
### Calculate size
function _format_bytes($a_bytes)
{
if ($a_bytes < 1024) {
return $a_bytes . ' B';
} elseif ($a_bytes < 1048576) {
return round($a_bytes / 1024, 2) . ' KB';
} elseif ($a_bytes < 1073741824) {
return round($a_bytes / 1048576, 2) . ' MB';
} elseif ($a_bytes < 1099511627776) {
@hnq90
hnq90 / Media-Query-Mario.markdown
Created July 28, 2014 03:26
A Pen by Ashley Nolan.

Media Query Mario

Mario 3 remade with CSS animation and media queries – a remake of a demo I did a while back for a MDN Dev Derby.

Best viewed if you have your view so that the code stacks on the right, so you can expand the main window rather than your whole browser (controlled in bottom right of CodePen or at this link).

I wanted to make playing around with the demo code a little bit easier not just for myself, but for anyone interested in messing with the code.

It benefits from being inside the CodePen window, as you can just resize the inbuilt CodePen window instead of the entire browser to make the animations fire!

@hnq90
hnq90 / getflickr.js
Last active August 29, 2015 14:04
Get link Flickr
// View Flickr source code
(function () {
var init = function () {
getflickr();
}
var topLargest = 3;
var orderSizesByHeight = function (sizes) {
var sz = [],
szLen, total, result = {};
@hnq90
hnq90 / parry-server
Last active August 29, 2015 14:05
Startup script for the Parry Server
#!/bin/bash
#
# parry-server Startup script for the Parry Server
#
# chkconfig: - 85 15
# description: PARRY Server Service
# author: HuyNQ <huynq@rikkeisoft.com>
# processname: parry-server
#
PARRY_HOME="parry-directory"
@hnq90
hnq90 / index.html
Last active August 29, 2015 14:06
Demo Websocket with NodeJS & Socket.IO (Client-side)
<html>
<head>
<title>WebSocket Client</title>
<script src="http://localhost:6666/socket.io/socket.io.js"></script>
<script>
window.onload = function(){
var input = document.getElementById('input');
var output = document.getElementById('output');
var socket = io.connect('localhost',{port: 5555});
socket.on("connect",function(){
@hnq90
hnq90 / server.js
Created September 12, 2014 02:35
Demo Websocket with NodeJS & Socket.io (Server-side)
var io = require('socket.io');
var socket = io.listen(6666);
socket.sockets.on('connection',function(socket){
socket.on('message', function(expr){
console.log('Received expression from client ',expr);
try{
socket.send(eval(expr));
} catch(err){
socket.emit("error",err.message);
}
@hnq90
hnq90 / gist:31c53e58eaa8686e1f17
Created September 19, 2014 08:25
Detect Json ecode error
$json = json_encode($output);
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
@hnq90
hnq90 / IOSPushNotification.php
Last active November 11, 2017 22:22
APNS-CakePHP
<?php
###
# Using APNS-PHP Library <https://github.com/duccio/ApnsPHP>
###
App::uses("String", "Utility");
App::uses("Security", "Utility");
App::import("Vendor", "ApnsPHP/Autoload");
require __DIR__ . '/PushNotificationInterface.php';
@hnq90
hnq90 / PushNotificationInterface.php
Created October 2, 2014 03:54
PushNotificationInterface
<?php
interface PushNotificationInterface
{
/**
* @param string $device_token Device Token
* @param string $text Content of notification
* @param array $options Options of push notification
*
* @return bool Push notification successfully or failed