Skip to content

Instantly share code, notes, and snippets.

@turboza
turboza / AJAX_Sample_Code.js
Last active December 20, 2015 01:59
AJAX Sample Code with JSON parsing
$.ajax({
url: "example.com/ex.json",
type: "get",
data: {var1:'value1',var2:'value2'},
dataType:'json',
success: function(content){
console.log(content.value);
},
error:function(){
console.log('error');
@turboza
turboza / moveViewUp.m
Created January 19, 2014 14:35
[iOS] Ready made Code for moving up the View up when you bring up the Keyboard Ref: http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present
#define kOFFSET_FOR_KEYBOARD 80.0
-(void)keyboardWillShow {
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
@turboza
turboza / Kernel.php
Created December 27, 2015 12:46
Workaround for Laravel 5.2 ErrorException: Undefined variable: errors (May not be minimal)
<?php
// Working code for Laravel 5.2.5 - Fix no $errors return
// Error Desc: ErrorException: Undefined variable: errors
// REF: https://laracasts.com/discuss/channels/laravel/errorexception-undefined-variable-errors
namespace App\Http;
@turboza
turboza / paramSerialize.js
Created September 20, 2016 13:14
Parameter serializer to create URL query string from nested objects.
/**
* =========================================
* paramSerialize
* =========================================
* Serialize JS object into URL Query string format.
*
* @param {object} params - { a: 10, filters: { x: 2, y: true } }
* @return {string} - '?a=10&filters[x]=2&filters[y]=true'
*/
export default function paramSerialize(params) {
@turboza
turboza / 1-closure-issue.js
Last active October 3, 2016 05:07
Closure gotcha
/*
* This code snippet give an unexpected result because the closure (function inside function)
* that will preserve the local variable "i" eventhough buildAction is finished
* So every action in array will refer to the same "i" which is 4 after finishing loop.
*
* Result :(
* ```
* "item 4 = undefined"
* "item 4 = undefined"
* "item 4 = undefined"
@turboza
turboza / omise_express_charge_card.js
Last active April 27, 2017 16:22
Sample of charging card using Node.js express
const omise = require('omise')({
secretKey: 'skey_test_...',
});
app.post('/pay', function(req, res) {
const tokenId = req.body.tokenId,
omise.charges.create({
description: 'Charge for order ID: 888',
amount: '100000', // 1,000 Baht
@turboza
turboza / clean_node_modules.sh
Created July 31, 2017 03:48
Recursively Clean all node_modules in your projects to save a lot of space
#!/bin/sh
find . -name "node_modules" -exec rm -rf '{}' +

Keybase proof

I hereby claim:

  • I am turboza on github.
  • I am turboza (https://keybase.io/turboza) on keybase.
  • I have a public key ASCKNEVoh1UZMz6lTnEiM7t4819Yo9feslX4TnD28EZGEwo

To claim this, I am signing this object:

@turboza
turboza / ecto_data_not_update_experiment.ex
Last active February 5, 2019 07:50
A confusing moment for Ecto when the data in the database is not updated when doing `Repo.update()`
defmodule Experiment do
alias SampleApp.{Repo, Order}
def run do
order = Repo.get(Order, 123)
order.status # => "new"
# Put status as "pending" while doing some action
{:ok, _} =
order