Skip to content

Instantly share code, notes, and snippets.

@pbakondy
pbakondy / parse-json.js
Created July 6, 2015 10:25
Parse JSON, strip BOM
// https://github.com/npm/npm/blob/master/lib/utils/parse-json.js
'use strict'
var parseJSON = module.exports = function (content) {
return JSON.parse(stripBOM(content))
}
parseJSON.noExceptions = function (content) {
try {
@pbakondy
pbakondy / httpRequest.m
Last active November 25, 2022 01:31
HTTP Request Objective-C implementations
#import <Foundation/Foundation.h>
@interface MyNetwork : NSObject
- (NSData* )httpRequestWithURL:(NSURL *)url httpMethod:(NSString *)httpMethod body:(NSData *)body contentType:(NSString *)contentType error:(NSError **)error;
@end
@implementation MyNetwork
@pbakondy
pbakondy / copyObject.js
Created June 25, 2015 13:51
Copy JS object in ES5 way
// http://speakingjs.com/es5/ch17.html#code_copyOwnPropertiesFrom
// To create an identical copy of an object, you need to get two things right:
// - The copy must have the same prototype as the original.
// - The copy must have the same properties, with the same attributes as the original.
function copyObject(orig, deep) {
// 1. copy has same prototype as orig
var copy = Object.create(Object.getPrototypeOf(orig));
@pbakondy
pbakondy / essential-javascript-functions.js
Created July 20, 2015 16:00
7 Essential JavaScript Functions
// http://davidwalsh.name/essential-javascript-functions
/*
debounce
The debounce function can be a game-changer when it comes to event-fueled performance.
If you aren't using a debouncing function with a scroll, resize, key* event, you're
probably doing it wrong. Here's a debounce function to keep your code efficient:
*/
@pbakondy
pbakondy / play.js
Last active June 7, 2021 22:08
Play with Object.prototype.toString.call()
// under Google Chrome 36
Object.prototype.toString.call([])
// "[object Array]"
Object.prototype.toString.call(function(){})
// "[object Function]"
Object.prototype.toString.call({})
// "[object Object]"
Object.prototype.toString.call(null)
// "[object Null]"
@pbakondy
pbakondy / main.dart
Created January 6, 2021 14:11
Fluffer Divider thickness
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Startup Name Generator',
@pbakondy
pbakondy / example.java
Created April 14, 2015 08:21
How to return boolean value in a cordova android plugin
// How to return boolean value in a cordova android plugin
public class ExampleClass extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("test")) {
try {
boolean result = testAction();
callbackContext.sendPluginResult(new PluginResult(Status.OK, result));
} catch (Exception e) {}
@pbakondy
pbakondy / isNotificationEnabled.java
Created July 20, 2015 10:01
Cordova - Push Notifications - Android - How to check notifications are disabled for the application?
// Cordova - Push Notifications - Android
// How to check notifications are disabled for the application?
// Works on Andoid 4.4+ (KitKat)
// Otherwise returns 'true'
// original:
// http://stackoverflow.com/questions/11649151/
public class NotificationsUtils {
@pbakondy
pbakondy / build-ios.sh
Last active January 6, 2017 11:42
build and sign ionic app iOS
# Test Build (armv7 only)
#
ionic platform remove ios
gulp useref
ionic platform add ios
cp assets/build/ios/build.xcconfig platforms/ios/cordova/build.xcconfig
ionic build ios --device
xcrun -sdk iphoneos PackageApplication -v platforms/ios/build/device/appname.app -o deployments/appname-test.ipa
/usr/bin/codesign --display platforms/ios/build/device/appname.app
/usr/bin/codesign --verify platforms/ios/build/device/appname.app