Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
body {
margin: 0;
padding: 0;
}
@shlomitc
shlomitc / reject-resolve
Last active August 29, 2015 14:20
rejected and resolved promises from jQuery
var getRejectedPromise = function(data){
if (typeof data !== 'undefined') {
data = [].concat(data);
}
var deferred = new jQuery.Deferred();
deferred.reject.apply(deferred, data);
return deferred.promise();
};
var getResolvedPromise = function(data){
function createMe(config){
return {
callMeString: function(){
console.log('who: ' + config);
},
callMeObject: function(){
console.log('who: ' + (config && config.who));
}
};
}
@shlomitc
shlomitc / Fetch - POST - JSON
Created June 21, 2016 14:09
How to use the fetch api to send a json object
fetch('http://localhost:4000/generate',
{
method: "POST",
headers: {
"Content-type": "application/json; charset=UTF-8"
},
body: JSON.stringify({a:1})
})
@shlomitc
shlomitc / gist:d050f0c2729002848ad4a146d24d4421
Created August 1, 2016 07:00
Get an angular service from console
angular.element(document.body).injector().get('serviceName');
@shlomitc
shlomitc / index.html
Last active August 10, 2016 19:30 — forked from anonymous/index.html
Angular Directive Compilation Order
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body ng-app="myApp">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<parent>
@shlomitc
shlomitc / example
Created December 29, 2016 12:09
React context usage and overriding example
import React from 'react';
class A extends React.Component {
render() {
return (
<div>
<h1>A</h1>
<B/>
</div>
);
@shlomitc
shlomitc / gql-apollo-test.spec.js
Last active January 20, 2018 02:27
A working example of graphql and apollo client test
import 'mocha';
import {expect} from 'chai';
import 'isomorphic-fetch';
import ApolloClient from 'apollo-client';
import gql from 'graphql-tag';
import {print} from 'graphql-tag/bundledPrinter';
describe('some test', () => {
it('should pass', () => {
import React from 'react';
import PropTypes from 'prop-types';
import styled, {ThemeProvider} from 'styled-components';
// Button/Button.js (The basic component)
const Button = ({className, children}) => (
<button className={className}>
{children}
</button>
);