Skip to content

Instantly share code, notes, and snippets.

View gor181's full-sized avatar

Goran Udosic gor181

  • Inflexus LTD
  • Croatia
View GitHub Profile
@gor181
gor181 / apple.ex
Last active April 9, 2024 09:59
Apple - API - Authentication
defmodule Project.AppleApi do
@moduledoc """
Apple API: https://developer.apple.com/documentation/appstoreserverapi/creating_api_keys_to_use_with_the_app_store_server_api
Relies on Confex and having the following configuration in config/config.exs
```
config :project, Project.Apple,
api_url: {:system, "PROJECT_APPLE_URL", ""},
certificate: {:system, "PROJECT_APPLE_CERTIFICATE", ""},
@gor181
gor181 / map-reduce.js
Last active July 19, 2017 20:36
simple reduce and map (from top of my head)
const reduce = (array, callback, initialValue) => {
let result;
for(let i = 0; i < array.length; i++) {
result = callback(result || initialValue, array[i], i);
}
return result;
};
//Example of underscore chaining
var users = [
{name: 'John', surname: 'Doe', age: 35},
{name: 'John 2', surname: 'Doe 2', age: 19},
{name: 'John 3', surname: 'Doe 3', age: 28},
{name: 'John 4', surname: 'Doe 4', age: 16},
{name: 'John 5', surname: 'Doe 5', age: 39}
];
//Iterate over users and sort them by age, pick first and transform to a sentence
@gor181
gor181 / objects-delegation-mutation.js
Last active October 27, 2017 10:14
Delegation, object mutation and how to avoid it. Javascript.
//Some of the examples use spread syntax available via Babel in ES7 proposal.
//Live at: https://jsbin.com/zawavekepo/edit?js,console
//Arrays, slicing and avoiding mutations
const numArray = [10, 20, 30, 40, 50, 60];
const removeAtIndex = (arr, x) => {
return [
...arr.slice(0, x),
...arr.slice(x + 1)
];
@gor181
gor181 / react-select.jsx
Created January 15, 2016 21:16
Simple select for React.
const React = require('react');
const classnames = require('classnames');
const { find, map } = require('lodash');
module.exports = React.createClass({
displayName: 'Select',
propTypes: {
types: React.PropTypes.arrayOf(
React.PropTypes.shape({
@gor181
gor181 / react-coffescript-test.js
Last active January 7, 2016 14:39
JSBin: React 0.14.3 + Coffeescript
customers = ['CustomerA', 'CustomerB', 'CustomerC']
{div} = React.DOM
App = React.createClass
render: ->
div {}, customers.map (c, i) -> div {key: i, className: ~~new Date()}, c
ReactDOM.render(
@gor181
gor181 / getNumbersOf.js
Last active September 9, 2015 13:30
Given an array of positive integers, write a function which returns all the unique pairs which add (equal) up to 100.
/*
Coding
Given an array of positive integers, write a function which returns all the unique pairs which add (equal) up to 100.
sample_input = [0, 1, 100, 99, 0, 10, 90, 30, 55, 33, 55, 75, 50, 51, 49, 50, 51, 49, 51]
sample_output = [[1,99], [0,100], [10,90], [51,49], [50,50]]
*/
var sample_input = [0, 1, 100, 99, 0, 10, 90, 30, 55, 33, 55, 75, 50, 51, 49, 50, 51, 49, 51];
var result = getNumbersOf(100, sample_input, true, []);
var http = require('http');
function follow(url, cb) {
http.get(url, function(res) {
res.on('data', function (chunk) {
var data = JSON.parse(chunk.toString());
if (!data || !data.follow) {
cb(data);
return;
}