Skip to content

Instantly share code, notes, and snippets.

View reyhansofian's full-sized avatar

Reyhan Sofian reyhansofian

View GitHub Profile
@antoniputra
antoniputra / macros.php
Created November 15, 2014 21:55
Macro for easily create link with method (POST, PUT, DELETE) - Laravel 4
<?php
/**
* Usage..
* Just save this code to your helpers file (eg: routes, filters, etc...)
*
* Then..
* {{ Form::link('Delete Item', 'DELETE', route('anything.page'), array('class' => 'btn btn-primary'), 'Are you sure ?') }}
**/
/*
* Utility to only call Redux updates in RequestAnimationFrame's
* Also uses React-dom's batchedUpdates
*/
import raf from 'raf';
import { unstable_batchedUpdates as batchedUpdates } from 'react-dom';
let rafID;
let notifyFunc;
function animFrame() {
@aldendaniels
aldendaniels / alternative-to-higher-order-components.md
Last active October 6, 2018 09:50
Alternative to Higher-order Components

React now supports the use of ES6 classes as an alternative to React.createClass().

React's concept of Mixins, however, doesn't have a corollary when using ES6 classes. This left the community without an established pattern for code that both handles cross-cutting concerns and requires access to Component Life Cycle Methods.

In this gist, @sebmarkbage proposed an alternative pattern to React mixins: decorate components with a wrapping "higher order" component that handles whatever lifecycle methods it needs to and then invokes the wrapped component in its render() method, passing through props.

While a viable solution, this has a few drawbacks:

  1. There's no way for the child component to override functionality defined on the higher order component.
@eiriklv
eiriklv / avoiding-exceptions.js
Last active February 2, 2019 12:13
Exception free JavaScript?
/**
* WHY? - BECAUSE EXCEPTIONS/TRY/CATCH IS A GLOBAL HORRIBLE MESS :-(
* Check out error handling in golang: https://blog.golang.org/error-handling-and-go
*/
/**
* Wrap an "unsafe" promise
*/
function safePromise(promise) {
return promise
@yang-wei
yang-wei / note.md
Last active April 19, 2021 14:49
Vue.js tips and tricks

Notes: All the examples below are only tested on Vue.js 1.0 (above).

Notes: The examples below use ES6 so it's recommended to use browserify or webpack to easily integrate babel.

when or where can we use this.$el

When you need to access DOM attribute, be careful with the lifecycle. Vue.js has a few useful lifecycle hooks.

Let's say we want to scroll our component to the bottom (imagine it's a long list with overflow-y: auto) once it's instantiate.

@wavded
wavded / promise.js
Last active May 6, 2021 13:25
Promise A+ Implementation
"use strict"
var Promise = function () {
this.state = 'pending'
this.thenables = []
}
Promise.prototype.resolve = function (value) {
if (this.state != 'pending') return
this.state = 'fulfilled'
@WebReflection
WebReflection / multiple-uploads.md
Last active June 30, 2021 14:12
Uploading multiple files at once, and without jQuery

The aim of this gist is to fix the following informative post about uploading via XHR.

Fixing the HTML

The first part is the HTML. First of all, you really don't need JavaScript to upload a file but you do need a proper form. Secondly, inputs in a form shouild have a name, because the name is what the server will receive: not IDs, names!

Following the fixed form part.

@techmexdev
techmexdev / delete-helm-chart-resources.sh
Last active October 15, 2022 20:54
Deletes the leftover resources after purging a chart. Workaround for: https://github.com/helm/helm/issues/6646
#!/usr/bin/env bash
ENV=$1
APP=$2
NAMESPACE=$3
FILENAME=upgrade-error.txt
while true
do
function upgrade() {
@blaisep
blaisep / jenkins-pipeline-git-cred.md
Created October 20, 2016 23:33
Insert git credentials into Jenkins Pipeline Script projects

Suppose you want to inject a credential into a Pipeline script. The cloudbees note does not include Pipeline script examples. https://support.cloudbees.com/hc/en-us/articles/203802500-Injecting-Secrets-into-Jenkins-Build-Jobs

The Jenkins Pipeline Docs' description of the git pushmethod doesn't have an example using injected credentials. (https://jenkins.io/doc/pipeline/examples/#push-git-repo)

The Snippet generator is helpful, but not not if you try to follow the instructions at: https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin