Skip to content

Instantly share code, notes, and snippets.

View NeverwinterMoon's full-sized avatar
💭
Hacking at SwiftUI

Pavel Sorokin NeverwinterMoon

💭
Hacking at SwiftUI
View GitHub Profile
@NeverwinterMoon
NeverwinterMoon / angular-loadscript.js
Created October 20, 2016 05:24 — forked from endorama/angular-loadscript.js
AngularJS 1.2.0 lazy load script in partials
/*
* Angular LoadScript
*
* Let angular load and execute lazy javascript from partials!
*
* This module is the result of this issue: "1.2.0rc1 regression: script tags not loaded via ngInclude"
* Issue url: https://github.com/angular/angular.js/issues/3756
*
* As of Angular 1.2.0 the ngInclude scripts does not permit execution of javascript from included partials.
* This little module execute code inside script tags with "javascript-lazy" attribute after partial loading,
/*
The MIT License (MIT)
Copyright (c) 2014 François de Campredon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@NeverwinterMoon
NeverwinterMoon / ActivityRealmRobolectricTest.java
Created December 19, 2016 17:43 — forked from jturolla/ActivityRealmRobolectricTest.java
This gist provides a simple example of mocking a Realm database for android in java using Robolectric.
package com.example;
import android.content.Intent;
import android.widget.Button;
import com.example.MockSupport;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@NeverwinterMoon
NeverwinterMoon / ResultTestActivity.java
Created March 15, 2017 11:22 — forked from saxophone/ResultTestActivity.java
Use Android Espresso to test that your Activity finishes with the expected result.
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static org.hamcrest.MatcherAssert.assertThat;
public class TilingDrawable extends android.support.v7.graphics.drawable.DrawableWrapper {
private boolean callbackEnabled = true;
public TilingDrawable(Drawable drawable) {
super(drawable);
}
@Override
public void draw(Canvas canvas) {
@NeverwinterMoon
NeverwinterMoon / GraphicGlDemoActivity.java
Created May 21, 2017 04:31 — forked from ybakos/GraphicGlDemoActivity.java
A simple example of using an Android Renderer to illustrate OpenGL ES boilerplate.
/* GraphicGlDemoActivity.java
* Author: Yong Bakos
* Since: 11/26/2012
* Thanks to:
* Cube: http://intransitione.com/blog/create-a-spinning-cube-with-opengl-es-and-android/
* OpenGL Boilerplate: http://www.jayway.com/2009/12/03/opengl-es-tutorial-for-android-part-i/
*/
package com.humanoriented.sudoku;
import java.nio.ByteBuffer;
@NeverwinterMoon
NeverwinterMoon / Main.elm
Created September 20, 2017 11:50 — forked from anonymous/Main.elm
Untitled
module Main exposing (main)
import Html exposing (Html, text)
import Date
import Date.Extra as Date
main : Html msg
main =
Html.div []
@NeverwinterMoon
NeverwinterMoon / NSAttributedStringConcatenation.swift
Created January 8, 2018 16:16 — forked from maxchuquimia/NSAttributedStringConcatenation.swift
Concatenate NSAttributedString in Swift without your code wrapping over multiple lines. Also adding images to attributed strings is supported!
func +(lhs: NSAttributedString, rhs: NSAttributedString) -> NSAttributedString {
let a = lhs.mutableCopy() as! NSMutableAttributedString
let b = rhs.mutableCopy() as! NSMutableAttributedString
a.appendAttributedString(b)
return a.copy() as! NSAttributedString
}
@NeverwinterMoon
NeverwinterMoon / Example.java
Created January 8, 2018 17:04 — forked from RyanRamchandar/Example.java
Cancel a running or queued Call with OkHttp3
// ...
Request request = new Request.Builder()
.url(url)
.tag(TAG)
.build();
// Cancel previous call(s) if they are running or queued
OkHttpUtils.cancelCallWithTag(client, TAG);
// New call
@NeverwinterMoon
NeverwinterMoon / Dictionary.swift
Created January 16, 2018 13:03 — forked from jordanekay/Dictionary.swift
Mapping dictionaries in Swift
extension Dictionary {
public func map<T: Hashable, U>(@noescape transform: (Key, Value) -> (T, U)) -> [T: U] {
var result: [T: U] = [:]
for (key, value) in self {
let (transformedKey, transformedValue) = transform(key, value)
result[transformedKey] = transformedValue
}
return result
}