Skip to content

Instantly share code, notes, and snippets.

View DavidVotrubec's full-sized avatar

David Votrubec DavidVotrubec

View GitHub Profile
@DavidVotrubec
DavidVotrubec / HtmlTextWriter_GetText_Demo
Created October 19, 2011 09:36
Get text value from HtmlTextWriter
var sb = new StringBuilder();
var sw = new StringWriter(sb);
using(var writer = new HtmlTextWriter(sw))
{
writer.AddAttribute(HtmlTextWriterAttribute.Href, someUrl);
writer.AddAttributeValues(HtmlTextWriterAttribute.Class, "actionCell", "download");
writer.AddAttributeIf(Target != null, HtmlTextWriterAttribute.Target, Target);
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.WriteEncodedText("Download");
@DavidVotrubec
DavidVotrubec / sg-readonly
Last active August 29, 2015 13:56
sg-readonly directive (written in TypeScript). Disables all nested fields when condition is met.
Module.directive("sgReadonly", [() => {
function toggleDisableAttr(fields:any[], isDisabled:boolean) {
_.each(fields, (f: any) => angular.element(f).prop('disabled', isDisabled));
}
return {
restrict: "A",
scope: {
isReadonly: '=sgReadonly',
@DavidVotrubec
DavidVotrubec / Less - Transition Mixin
Created May 20, 2014 07:25
Mixin for css transition
.transition(@property, @duration: 1s){
-webkit-transition: @property @duration;
-moz-transition: @property @duration;
-ms-transition: @property @duration;
-o-transition: @property @duration;
transition: @property @duration;
}
app.directive('someDirective', function () {
return {
scope: {
oneWay: '@',
twoWay: '=',
expr: '&'
}
};
});
nl2br(str) {
var newStr = str.split('\n').map(function(item) {
const key = Math.random() * (9999999 - 1) + 1;
return (
<span key={key}>
{item}
<br/>
</span>
)
@DavidVotrubec
DavidVotrubec / nl2br_in_ember.js
Last active May 12, 2016 07:25
Newline to <br/> in EmberJS
nl2br(str) {
var newStr = str.split('\n').map(function(item) {
const key = Math.random() * (9999999 - 1) + 1;
return (
<span key={key}>
{item}
<br/>
</span>
)
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myStrings: ['bla', 'asd', 'zzz', 'fgh'],
computedStrings: Ember.computed('myStrings.[]', function() {
return this.get('myStrings')
.map(aString => Ember.String.capitalize(aString));
}),
actions: {
@DavidVotrubec
DavidVotrubec / controllers.application.js
Last active June 15, 2016 21:43
Confirmation-Dialog
import Ember from 'ember';
export default Ember.Component.extend({
itemToDelete: null,
hasItemToDelete: Ember.computed('itemToDelete', function(){
return this.get('itemToDelete') != null;
}),
_closeConfirmationDialog: function() {
@DavidVotrubec
DavidVotrubec / controllers.application.js
Last active June 15, 2016 21:41
Confirmation-Dialog-3
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
items: [
{id: 1, name: 'first item'},
{id: 2, name: 'second item'},
{id: 3, name: 'third item'},
{id: 4, name: 'fourth item'},
@DavidVotrubec
DavidVotrubec / web3.js
Created October 15, 2018 07:23
Instance of web3 with provider from web3 injected by MetaMask
import Web3 from 'web3';
// We are assumming that the user has installed the Metamask browser extension
// and we are using Provider from the injected instance of web3
// to create instance of Web3 of our desired version
// See https://www.udemy.com/ethereum-and-solidity-the-complete-developers-guide/learn/v4/t/lecture/9020582?start=0 for more details
// This way we can simply import preconfigured instance of web3
const web3 = new Web3(window.web3.currentProvider);
export default web3;