Skip to content

Instantly share code, notes, and snippets.

View anggiaj's full-sized avatar

anggiaj anggiaj

  • Jakarta, Indonesia
View GitHub Profile
@anggiaj
anggiaj / require-uncached.js
Created December 23, 2016 22:59
node js require uncached module
function requireUncached(module) {
delete require.cache[require.resolve(module)];
return require(module);
}
@anggiaj
anggiaj / match-all.js
Created November 30, 2016 12:56
php like preg_match_all function
// NOTE: make sure your engine supports tail-call optimization
function matchAll(re, text) {
return (function find(acc) {
const match = re.exec(text);
if (match) {
acc.push(match);
return find(acc);
}
return acc;
})([]);
# find something that has more than one of something
Account.joins(:users).select('accounts.id').group('accounts.id').having('count(users.id) > 1')
Sidekiq.redis { |conn| conn.flushdb }
ActiveRecord::Base.connection.tables.collect{|table_name| ActiveRecord::Base.connection.execute("TRUNCATE #{table_name} RESTART IDENTITY")}
@anggiaj
anggiaj / introrx.md
Created January 26, 2016 06:43 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@anggiaj
anggiaj / adi.html
Last active October 30, 2015 09:37
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html>
<head>
<title>Adi</title>
<script src="http://yourjavascript.com/2223141713/purple-flower-effect-spiceupyourblog.js">
</script>
<style type="text/css">
#adi {
width:0px;
margin: 200px auto;

Installing a Gem on Heroku from a Private GitHub Repo

Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.

Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.

  1. Get an OAuth Token from GitHub

First you will need to get an OAuth Token from GitHub using your own username and "note"

// Lefalet shortcuts for common tile providers - is it worth adding such 1.5kb to Leaflet core?
L.TileLayer.Common = L.TileLayer.extend({
initialize: function (options) {
L.TileLayer.prototype.initialize.call(this, this.url, options);
}
});
(function () {
require 'faraday'
require 'json'
URL = 'https://anggiaj.buddycloud.com/api'
conn = Faraday.new
conn.basic_auth 'thoriq@anggiaj.buddycloud.com', 'cencoredpassword'
res = conn.post "#{URL}/thoriq@anggiaj.buddycloud.com/content/posts", { content: 'Hello world' }.to_json, 'Content-type' => 'application/json'
# response body
{