Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block BetterProgramming

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ConstraintLayout.xml
< xmlns:android=""
View threadnewdo.rb
threads << do ActiveRecord::Base.connection_pool.with_connection do
# needed because otherwise the connection pool can run
# out of connections
t = Thread.current
t[:variable_name] = Model.find_by(column: data)
joined_threads = &:join
# do something with the thread local variable
View thing1.js
state = {
questions: [
{ id: 'fdsd', title: 'Why is the sky blue?' },
{ id: 'adsf', title: 'Who invented pizza?' },
{ id: 'afdsf', title: 'Is green tea overrated?' },
displayQuestions: false
View geolocation.js
if ("geolocation" in navigator) {
// check if geolocation is supported/enabled on current browser
function success(position) {
// for when getting location is a success
console.log('latitude', position.coords.latitude,
'longitude', position.coords.longitude);
function error(error_message) {
// for when getting location results in an error
View sessionsController.js
const express = require('express');
const router = express.Router();
const CryptoJS = require("crypto-js");
const oauth = require('oauth');
const _twitterConsumerKey = process.env.TWITTER_CONSUMER_KEY;
const _twitterConsumerSecret = process.env.TWITTER_CONSUMER_SECRET;
const twitterCallbackUrl = process.env.TWITTER_CALLBACK_URL;
const consumer = new oauth.OAuth("", "",_twitterConsumerKey, _twitterConsumerSecret, "1.0A", twitterCallbackUrl, "HMAC-SHA1");
router.get('/connect', (req, res) => {
consumer.getOAuthRequestToken(function (error, oauthToken, oauthTokenSecret, results) {
View express.js
var express = require('express')
,cors = require('cors')
, app = express();
// after the code that uses bodyParser and other cool stuff
var originsWhitelist = [
'http://localhost:4200', //this is my front-end url for development
View nest6.js
FileInterceptor('image', {
storage: diskStorage({
destination: './files',
filename: editFileName,
fileFilter: imageFileFilter,
View nest5.js
export const editFileName = (req, file, callback) => {
const name = file.originalname.split('.')[0];
const fileExtName = extname(file.originalname);
const randomName = Array(4)
.map(() => Math.round(Math.random() * 16).toString(16))
callback(null, `${name}-${randomName}${fileExtName}`);
View nest4.js
export const imageFileFilter = (req, file, callback) => {
if (!file.originalname.match(/\.(jpg|jpeg|png|gif)$/)) {
return callback(new Error('Only image files are allowed!'), false);
callback(null, true);
View nest3.js
FilesInterceptor('image', 20, {
storage: diskStorage({
destination: './files',
filename: editFileName,
fileFilter: imageFileFilter,
You can’t perform that action at this time.