Skip to content

Instantly share code, notes, and snippets.

View cyrilf's full-sized avatar
🌱
what's up!

cyril cyrilf

🌱
what's up!
View GitHub Profile
@cyrilf
cyrilf / includedByState-example.js
Last active August 29, 2015 14:14
includedByState filter improvement
// Improvement proposal
$IncludedByStateFilter.$inject = ['$state'];
function $IncludedByStateFilter($state) {
var includesFilter = function (state, params, options) {
return $state.includes(state, params, options);
};
includesFilter.$stateful = true;
return includesFilter;
}
@cyrilf
cyrilf / rmTopFrame.js
Created December 20, 2012 22:02
Remove Google Images Frame on your site and close it.
if (top.location != self.location)
top.location = self.location;
@cyrilf
cyrilf / getNumber.js
Created December 21, 2012 22:05
A little improvement of parseFloat function to handle string in ending with %.
var f = getNumber('23.7'); // f = 23.7
//var f = getNumber(23.7); // f = 23.7
//var f = getNumber('23.7 px'); // f = 23.7
//var f = getNumber('23.7 %'); // f = 0.237
function getNumber(input) {
if( typeof input === 'string' && input.slice(-1) === '%') {
input = parseFloat(input.slice(0,-1))/100;
} else {
input = parseFloat(input);
@cyrilf
cyrilf / zlogin Ezio
Created March 7, 2013 08:36
Zlogin for ZSH [Ezio]
#Zlogin by Cyril F [Ezio]
echo "
_|_|_|_| _|
_| _|_|_|_| _|_|
_|_|_| _| _| _| _|
_| _| _| _| _|
_|_|_|_| _|_|_|_| _| _|_| "
echo -e "\e[0;35m
@cyrilf
cyrilf / saveWAH.js
Created April 12, 2013 01:01
Save your We Are Hunted playlist. Download all your We Are Hunted tracks infos in a JSON file.
// Save your We Are Hunted playlist
// Download all your We Are Hunted tracks infos in a JSON file
// by Cyril F (github.com/cyrilf)
// Instructions
//
// Go to wearehunted.com
// Change the USERNAME below by your username or email.
// Copy and paste the following code into your javascript
// console.
@cyrilf
cyrilf / hasNestedProperties.js
Created June 11, 2013 16:34
Helper functions in JavaScript
/**
* hasNestedProperties check if an object has the nested
* properties passed in params
*
* @param {Object} obj object we want to test
* @param {String} properties nested property we want
* @return {Boolean} either the object has these
* nested properties or not
*/
@cyrilf
cyrilf / ZfcUserZendDb.php
Created July 23, 2013 15:07
BjyAuthorize issue #170
<?php
/**
* BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
*
* @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace BjyAuthorize\Provider\Identity;
@cyrilf
cyrilf / hoc.js
Created January 17, 2018 11:46
React custom life-cycle method
// Inspired by https://github.com/MicheleBertoli/react-automata/blob/d9128bebe30df83c41bff4ed806549241fcf3b04/src/withStatechart.js
// Example of how to use a custom life-cycle method for a wrapped component
import React from 'react'
const isStateless = Component =>
!(Component.prototype && Component.prototype.isReactComponent)
const withSomething = Component => {
// Utility function to get access nested object properties securely
//
// Usage:
// const invoiceName = get(account, "user.invoiceAddress.name")
//
// Instead of:
// const invoiceName = (account && account.user && account.user.invoiceAddress && account.user.invoiceAddress.name) || null
// https://stackoverflow.com/a/23809123/1410020
const get = (obj, key) =>
@cyrilf
cyrilf / proxy.js
Last active June 21, 2018 12:38
Proxy
// From: https://stackoverflow.com/questions/50963215/can-we-specify-a-generic-getter-on-an-object-in-javascript
// Allows you to access nested property (1 level) without the need to to safety check
const properties = { email: { title: "Email", value: "xyz@gh.com" } }
const proxy = new Proxy(properties, {
get: (target, prop) => (prop in target) ? target[prop] : {},
})
// or