Skip to content

Instantly share code, notes, and snippets.

{
"id": 3,
"content": "My awesome post",
"comments": [
{ "id": 3, "content": "This should be the first comment"},
{ "id": 6, "content": "This should be the second comment"}
]
}
@kuon
kuon / tables
Created February 2, 2017 14:11
Table "public.posts"
Column | Type | Modifiers
---------+---------+----------------------------------------------------
id | integer | not null default nextval('posts_id_seq'::regclass)
content | text |
Indexes:
"posts_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "comments" CONSTRAINT "comments_post_id_fkey"
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE
@kuon
kuon / upload.js
Created January 29, 2017 13:54
Java to javascript file upload
export function readFile() {
let path = Android.imagePath();
let base64 = Android.imageData();
// If there is an escaped / in the name, this will produce wrong result
// but still give proper type
let filename = path.split('/').pop();
let type = getType(filename);
let byteString = atob(base64);
@kuon
kuon / activity.java
Created January 29, 2017 13:52
Upload interface for android
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == SELECT_PICTURE
&& resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
@kuon
kuon / upload.java
Created January 29, 2017 13:51
Android file upload
//For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUM = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"), FCR);
}
// For Android 3.0+, above method not supported in some android 3+ versions,
@kuon
kuon / stepped-gradient.scss
Created January 29, 2017 11:50
Stepped gradient
$g: transparent;
$steps: 10;
@for $i from 1 to $steps {
$g: append($g, fade-out($bg-color, 1 / $i) percentage($i / $steps), comma);
$g: append($g, fade-out($bg-color, 1 / $i) percentage(($i + 0.6) / $steps), comma);
}
$g: append($g, $bg-color);
background: linear-gradient(to bottom, $g);
@kuon
kuon / Makefile
Created January 29, 2017 10:54
Wrap a Rakefile with make
RAKE_TASKS = $(shell bundle exec rake -T |cut -d ' ' -f 2| sed s/:/\\\\:/g )
.PHONY: ${RAKE_TASKS}
${RAKE_TASKS}:
bundle exec rake $@
@kuon
kuon / watch.js.diff
Created January 5, 2017 05:51
brunch multiple compilers
diff --git a/lib/watch.js b/lib/watch.js
index 4140528..9421446 100644
--- a/lib/watch.js
+++ b/lib/watch.js
@@ -316,9 +316,34 @@ class BrunchWatcher {
this.fileList.emit('change', path, compiler, [], isHelper);
} else {
const isFor = plugin => plugin.pattern.test(path);
- const compiler = this.plugins.compilers.filter(isFor);
const currentLinters = this.plugins.linters.filter(isFor);
@kuon
kuon / MWApplication.m
Created December 20, 2016 17:43
NSApp fun
#include "nw_private.h"
#include "NWApplication.h"
#include "NWApplicationView.h"
#include "nw_application.h"
#include "nw_keyboard.h"
#include "nw_geometry.h"
#include "nw_opengl.h"
#include "nw_timer.h"
#include "nw_autorelease_pool.h"
SECRET=`cat config/prod-staging.secret.exs`
local _prod_secret_path="/home/builder/prod.secret.exs"
if [ "$TARGET_MIX_ENV" = "prod" ]; then
__sync_remote "
printf '%s\n' '$SECRET' > '$BUILD_AT/config/prod.secret.exs'
"
fi