Skip to content

Instantly share code, notes, and snippets.

BetterProgramming

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
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="80dp"
android:paddingBottom="8dp">
<ImageView
android:id="@+id/ivotp"
android:layout_width="16dp"
android:layout_height="16dp"
View threadnewdo.rb
threads << Thread.new 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)
end
end
joined_threads = threads.map &: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
navigator.geolocation.getCurrentPosition(
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("https://twitter.com/oauth/request_token", "https://twitter.com/oauth/access_token",_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();
//app.user(bodyParser.json());
// after the code that uses bodyParser and other cool stuff
var originsWhitelist = [
'http://localhost:4200', //this is my front-end url for development
'http://www.myproductionurl.com'
];
View nest6.js
@Post()
@UseInterceptors(
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)
.fill(null)
.map(() => Math.round(Math.random() * 16).toString(16))
.join('');
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
@Post('multiple')
@UseInterceptors(
FilesInterceptor('image', 20, {
storage: diskStorage({
destination: './files',
filename: editFileName,
}),
fileFilter: imageFileFilter,
}),
)
You can’t perform that action at this time.