Skip to content

Instantly share code, notes, and snippets.

View brickpop's full-sized avatar

Jør∂¡ brickpop

View GitHub Profile
@brickpop
brickpop / context-example.tsx
Last active July 1, 2021 09:19
React Hooks quick examples
// THE CONTEXT REFERENCE
const MyCounterContext = createContext<{ counter: number, setCounter: (n: number) => void }>({ counter: 0, setCounter: () => { } })
// PROVIDES ITS STATE TO CHILDREN COMPONENTS
const MyParent = ({ children }) => {
const [counter, setCounter] = useState(0)
return <MyCounterContext.Provider value={{ counter, setCounter }}>
{children}
</MyCounterContext.Provider>
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
@brickpop
brickpop / viewpager-android-wrapper.js
Created September 8, 2018 23:39
Wrapper to fix a bug in ViewPagerAndroid when combined with React Navigation
import React, { PureComponent } from 'react';
import {
View,
Dimensions,
Platform
} from 'react-native';
export default class ViewPagerWrapper extends PureComponent {
constructor(props) {
super(props);
@brickpop
brickpop / eth-address-generator.js
Created July 6, 2017 00:31
Ethereum utilities
// Generate a private key => address from a passphrase
const passphrase = process.argv[2];
if(!passphrase) {
console.log("Usage: node app 'your-passphrase-here'");
process.exit();
}
const EthUtil = require("ethereumjs-util")
const Web3 = require('web3')
@brickpop
brickpop / ng-admin-uploader.js
Last active May 17, 2017 08:54
NG Admin Custom upload directive
app.directive('uploader', ['$http', '$q', 'notification', '$state', function ($http, $q, notification, $state) {
return {
restrict: 'E',
scope: {
prefix: '&',
suffix: '&'
},
link: function ($scope) {
$scope.uploaded = false;
@brickpop
brickpop / fcm-ios-react-native.txt
Last active February 1, 2017 23:48
FCM for iOS HowTo
# Extra info:
# https://firebase.google.com/docs/ios/setup
react-native init Twins
cd Twins
react-native run-ios
yarn add react-native-fcm
react-native link react-native-fcm
@brickpop
brickpop / nginx-proxy.conf
Last active August 14, 2019 12:43
Example of an nginx virtual host with a selective cached reverse proxy
# TO DO
# - Replace '9000' with your local port
#
# - Run certbot to geherate a certificate for domain-name.com and uncoment the HTTPS section below
# $ certbot certonly --webroot -w /var/www/certbot -d www.domain-name.com -d domain-name.com
upstream app-server {
ip_hash;
server: localhost:9000;
# server: localhost:9001; # used if clustering is available
@brickpop
brickpop / sha-digest.js
Created November 16, 2016 19:17
Password digest for NodeJS
var crypto = require('crypto');
function digestPwd(password){
var shasum = crypto.createHash('sha1');
shasum.update(password);
return shasum.digest('hex');
}
module.exports = digestPwd;
@brickpop
brickpop / config-default.js
Last active November 16, 2016 16:30
Example of a dev/production/env config system for NodeJS
// These are de default settings
// They may be overriden by the values in cofig-production.js if NODE_ENV=production
// They may also be averriden if an environment variable with the same name is set
// WARNING: Do not include this file directly. Use config.js instead
module.exports = {
DEBUG: true,
COMPONENT_NAME: 'PROJECT API',
HTTP_PORT: 8000,
@brickpop
brickpop / agnoster.zsh-theme
Created November 6, 2016 23:01
Customized ZSH Theme
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline