Skip to content

Instantly share code, notes, and snippets.

@n1ru4l
n1ru4l / parseDuration.js
Created June 18, 2016 12:50
Convert mediainfo duration to seconds
function parseDuration(duration) {
let durationInSeconds = 0
const hourIndex = duration.indexOf('h')
if(hourIndex > -1) {
let hours = parseInt(duration.substr(0, hourIndex), 10)
duration = duration.substr(hourIndex + 1)
durationInSeconds += hours * 60 * 60
}
@n1ru4l
n1ru4l / esnextbin.md
Last active July 13, 2016 08:11
esnextbin sketch
@n1ru4l
n1ru4l / ArtistList.js
Created January 24, 2017 15:42
mobx + apollo-client + react
import React from 'react'
import { observer } from 'mobx-react'
function ArtistList({ uiState: { artistData } }) {
const { data } = artistData;
if ( !data || !data.artists || !data.artists.length ) {
return <div>No artists bruh.</div>
}
const { artists } = data
return (
@n1ru4l
n1ru4l / components.query-wrapper.js
Last active May 18, 2017 05:47
Ember Graphql Query Component
import Ember from 'ember';
import gql from 'graphql-tag'
const query = gql`
query pokedex {
pokedex {
pokemon(start: 0 number: 10) {edges {node {id name}}}
}
}
`
@n1ru4l
n1ru4l / components.some-component.js
Last active May 23, 2017 16:04
array not updating
import Ember from 'ember';
import {
times,
constant
} from 'lodash';
const {
get,
set,
Component,
import Ember from 'ember';
const {
Component,
on,
computed,
A: EArray,
} = Ember;
export default Component.extend({
@n1ru4l
n1ru4l / HTTPGetRequestForQueriesInterface.js
Created May 30, 2017 14:46
HTTPGetRequestForQueriesInterface
import { HTTPFetchNetworkInterface, printAST } from 'apollo-client';
/**
* Serialize a object to a query string
* @source https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascript-object#comment47677757_18116302
*/
function serialize( obj ) {
return `?` + Object.keys(obj).map(k => k + `=` + encodeURIComponent(obj[k])).join(`&`);
}
@n1ru4l
n1ru4l / controllers.application.js
Created June 10, 2017 13:41
onChange event demonstartion
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
model: {
sumText: 'sum text',
},
actions: {
changed() {
alert('onChange triggered')
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
foo() {
alert('red box')
},
bar(ev) {
@n1ru4l
n1ru4l / EventServiceProvider.php
Created July 31, 2017 13:27
Laravel realpath_cache clearing
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{